Skip to content

Instantly share code, notes, and snippets.

@kylefox
Created December 4, 2009 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylefox/248890 to your computer and use it in GitHub Desktop.
Save kylefox/248890 to your computer and use it in GitHub Desktop.
# 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