Created
December 4, 2009 07:32
-
-
Save kylefox/248890 to your computer and use it in GitHub Desktop.
This file contains 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
# Simple script to determine name, lat/long and timezone of a place name. | |
import urllib2 | |
import pytz | |
import json | |
from geocoders.geonames import geocode | |
def get_timezone(lat, lng): | |
url = "http://ws.geonames.org/timezoneJSON?lat=%s&lng=%s" % (lat, lng) | |
data = urllib2.urlopen(url) | |
return pytz.timezone(json.load(data)[u'timezoneId']) | |
def locate(place): | |
name, coords = geocode(place) | |
tz = get_timezone(*coords) | |
return (name, coords, tz) | |
print locate("Edmonton, alberta") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment