Created
July 29, 2014 16:55
-
-
Save darthwade/b5f2ca9618c52bfaae13 to your computer and use it in GitHub Desktop.
Grab geonames 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 geonames from http://download.geonames.org/export/dump/ | |
>>> COUNTRY = 'UA' | |
>>> DOWNLOAD_URL = 'http://download.geonames.org/export/dump/{country}.zip'.format(country=COUNTRY) | |
>>> FILENAME = '{country}.txt'.format(country=COUNTRY) | |
>>> from urllib2 import urlopen | |
>>> import zipfile | |
>>> from cStringIO import StringIO | |
>>> rawzip = urlopen(DOWNLOAD_URL).read() | |
>>> zipdata = StringIO() | |
>>> zipdata.write(rawzip) | |
>>> myzipfile = zipfile.ZipFile(zipdata) | |
>>> f = myzipfile.open(FILENAME) | |
>>> lines = f.readlines() | |
>>> from apps.gis.models import City | |
>>> for l in lines: | |
>>> if not len(l): break | |
>>> (geonameid, name, asciiname, alternatenames, latitude, longitude, feature_class, feature_code, country_code, | |
>>> cc2, admin1, admin2, admin3, admin4, population, elevation, dem, timezone, modification_date) = l.split('\t') | |
>>> print name, alternatenames, latitude, longitude, population |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment