Skip to content

Instantly share code, notes, and snippets.

@danhammer
Created April 8, 2014 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danhammer/10199704 to your computer and use it in GitHub Desktop.
Save danhammer/10199704 to your computer and use it in GitHub Desktop.
Grab the NGO coordinates from bettermap.org
import requests
import pandas
from BeautifulSoup import BeautifulSoup
def _grab_data():
url = 'http://www.bettermap.org/json'
x = requests.get(url)
return x.json()['features']
def _process_entry(entry):
htmltag = entry['properties']['name']
soup = BeautifulSoup(htmltag)
lon,lat = map(float, entry['geometry']['coordinates'])
return {'ngo': soup.a.text, 'latitude': lat, 'longitude': lon}
def saveNGOs(filename="ngo.csv"):
raw = _grab_data()
dicts = map(_process_entry, raw)
df = pandas.DataFrame(dicts)
df.to_csv(filename)
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment