Created
February 8, 2016 16:13
-
-
Save alexrutherford/caf183fea21ff774480d to your computer and use it in GitHub Desktop.
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 | |
from secrets import key | |
def getCountry(s): | |
''' | |
Takes address string as input, queries Google geocoding API and returns country as ISO code | |
''' | |
tempUrl='http://maps.googleapis.com/maps/api/geocode/json?address=%s' % (s) | |
res=requests.get(tempUrl) | |
if len(res.json()['results'])==0: | |
return None | |
for comp in res.json()['results'][0]['address_components']: | |
#print comp.keys() | |
#print '\t',comp['types'] | |
if u'country' in comp['types']: | |
#print '\t', | |
return comp['short_name'] | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment