Skip to content

Instantly share code, notes, and snippets.

@darthwade
Created July 29, 2014 16:55
Show Gist options
  • Save darthwade/b5f2ca9618c52bfaae13 to your computer and use it in GitHub Desktop.
Save darthwade/b5f2ca9618c52bfaae13 to your computer and use it in GitHub Desktop.
>>> # 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