Created
July 29, 2014 08:50
-
-
Save darthwade/6496646a75a924f4cbcd to your computer and use it in GitHub Desktop.
Grab timezones from http://download.geonames.org/export/dump/
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
>>> # Grab timezones from http://download.geonames.org/export/dump/ | |
>>> DOWNLOAD_URL = 'http://download.geonames.org/export/dump/timeZones.txt' | |
>>> from urllib2 import urlopen | |
>>> lines = urlopen(DOWNLOAD_URL).read().split('\n')[1:] | |
>>> from apps.gis.models import TimeZone, Country | |
>>> for l in lines: | |
>>> if not len(l): break | |
>>> country_code, id, gmt_offset, dst_offset, raw_offset = l.split() | |
>>> try: | |
>>> country = Country.objects.get(id=country_code) | |
>>> defaults = {'country': country, 'gmt_offset': gmt_offset, 'dst_offset': dst_offset, 'raw_offset': raw_offset} | |
>>> (obj, created) = TimeZone.objects.get_or_create(id=id, defaults=defaults) | |
>>> for k,v in defaults.items(): | |
>>> setattr(obj, k, v) | |
>>> obj.save() | |
>>> print id, obj | |
>>> except Country.DoesNotExist: | |
>>> pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment