Created
November 20, 2012 03:35
-
-
Save erzr/4115787 to your computer and use it in GitHub Desktop.
Yahoo GeoPlanet (WOEID) Lookup In Python
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 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'] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)