Created
April 8, 2014 22:01
-
-
Save danhammer/10199704 to your computer and use it in GitHub Desktop.
Grab the NGO coordinates from bettermap.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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