Skip to content

Instantly share code, notes, and snippets.

@emre
Created October 24, 2013 12:53
Show Gist options
  • Select an option

  • Save emre/7136689 to your computer and use it in GitHub Desktop.

Select an option

Save emre/7136689 to your computer and use it in GitHub Desktop.
import cities
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand, CommandError
from main.models import Cities
from mongoengine.queryset import DoesNotExist
CITY_LIST = [
('01', u'Adana'),
('02', u'Adıyaman'),
('03', u'Afyon'),
('04', u'Ağrı'),
('05', u'Amasya'),
('06', u'Ankara'),
('07', u'Antalya'),
('08', u'Artvin'),
('09', u'Aydın'),
('10', u'Balıkesir'),
('11', u'Bilecik'),
('12', u'Bingöl'),
('13', u'Bitlis'),
('14', u'Bolu'),
('15', u'Burdur'),
('16', u'Bursa'),
('17', u'Çanakkale'),
('18', u'Çankırı'),
('19', u'Çorum'),
('20', u'Denizli'),
('21', u'Diyarbakır'),
('22', u'Edirne'),
('23', u'Elazığ'),
('24', u'Erzincan'),
('25', u'Erzurum'),
('26', u'Eskişehir'),
('27', u'Gaziantep'),
('28', u'Giresun'),
('29', u'Gümüşhane'),
('30', u'Hakkari'),
('31', u'Hatay'),
('32', u'Isparta'),
('33', u'Mersin'),
('34', u'İstanbul'),
('35', u'İzmir'),
('36', u'Kars'),
('37', u'Kastamonu'),
('38', u'Kayseri'),
('39', u'Kırklareli'),
('40', u'Kırşehir'),
('41', u'Kocaeli'),
('42', u'Konya'),
('43', u'Kütahya'),
('44', u'Malatya'),
('45', u'Manisa'),
('46', u'K.Maraş'),
('47', u'Mardin'),
('48', u'Muğla'),
('49', u'Muş'),
('50', u'Nevşehir'),
('51', u'Niğde'),
('52', u'Ordu'),
('53', u'Rize'),
('54', u'Sakarya'),
('55', u'Samsun'),
('56', u'Siirt'),
('57', u'Sinop'),
('58', u'Sivas'),
('59', u'Tekirdağ'),
('60', u'Tokat'),
('61', u'Trabzon'),
('62', u'Tunceli'),
('63', u'Şanlıurfa'),
('64', u'Uşak'),
('65', u'Van'),
('66', u'Yozgat'),
('67', u'Zonguldak'),
('68', u'Aksaray'),
('69', u'Bayburt'),
('70', u'Karaman'),
('71', u'Kırıkkale'),
('72', u'Batman'),
('73', u'Şırnak'),
('74', u'Bartın'),
('75', u'Ardahan'),
('76', u'Iğdır'),
('77', u'Yalova'),
('78', u'Karabük'),
('79', u'Kilis'),
('80', u'Osmaniye'),
('81', u'Düzce')
]
class Command(BaseCommand):
args = ''
help = 'imports cities to the database'
def handle(self, *args, **options):
for city in CITY_LIST:
try:
city = Cities.objects.get(code=city[0])
except DoesNotExist:
city = Cities(code=city[0], name=city[1], status=True)
city.save()
print 'saved {0}.'.format(city.name.encode('UTF-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment