Last active
August 29, 2015 14:04
-
-
Save darthwade/05b3044a5b964a74549d to your computer and use it in GitHub Desktop.
Grab countries in any language from https://github.com/umpirsky/country-list/blob/master/country/cldr
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 countries from https://github.com/umpirsky/country-list/blob/master/country/cldr | |
>>> LANG = 'uk' | |
>>> FIELD_SUFFIX = '_uk' | |
>>> DOWNLOAD_URL = 'https://raw.githubusercontent.com/umpirsky/country-list/master/country/cldr/{lang}/country.txt' | |
>>> from urllib2 import urlopen | |
>>> lines = urlopen(DOWNLOAD_URL.format(lang=LANG)).read().split('\n') | |
>>> from apps.gis.models import Country | |
>>> for l in lines: | |
>>> if not len(l): break | |
>>> l = l.decode('utf-8') | |
>>> name = l[:-5] | |
>>> id = l[-3:-1] | |
>>> defaults = {'name' + FIELD_SUFFIX: name} | |
>>> (obj, created) = Country.objects.get_or_create(id=id, defaults=defaults) | |
>>> for k,v in defaults.items(): | |
>>> setattr(obj, k, v) | |
>>> obj.save() | |
>>> print id, obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment