Created
December 29, 2013 23:58
-
-
Save drcjar/8176185 to your computer and use it in GitHub Desktop.
script to take a country name and return a woeid using yahoo api
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 | |
def get_woeid(text): | |
if not text: | |
return | |
app_id = "YOUR YAHOO APP ID" | |
if not app_id: | |
raise NotImplementedError('WOEID App Id is empty.') | |
url = 'http://where.yahooapis.com/v1/places.q(\'%s\')?appid=%s&format=json' % (text, app_id) | |
r = requests.get(url) | |
name = r.json()['places']['place'][0]['name'] | |
woeid = r.json()['places']['place'][0]['woeid'] | |
return {'name':name, | |
'woeid':woeid} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment