Skip to content

Instantly share code, notes, and snippets.

@erzr
Created November 20, 2012 03:35
Show Gist options
  • Select an option

  • Save erzr/4115787 to your computer and use it in GitHub Desktop.

Select an option

Save erzr/4115787 to your computer and use it in GitHub Desktop.
Yahoo GeoPlanet (WOEID) Lookup In Python
import requests
from django.conf import settings
def get_woeid(text):
if not text:
return
app_id = settings.WOEID_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)
json = r.json
places = json['places']
if not places['count']:
return
place = places['place'][0]
return {
'woeid': place['woeid'],
'name': place['name']
}
@EMCestari
Copy link

Thanks for this code, I would just give a suggestion:
I believe there is an error at line 19:
It should be:
json = r.json()
(parentheses were omitted in the original code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment