Skip to content

Instantly share code, notes, and snippets.

@drcjar
Created December 29, 2013 23:58
Show Gist options
  • Save drcjar/8176185 to your computer and use it in GitHub Desktop.
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
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