parent
ce857f4140
commit
be10fba319
11 changed files with 17 additions and 86 deletions
@ -1 +0,0 @@ |
||||
__author__ = 'kotzilla' |
||||
@ -1 +0,0 @@ |
||||
__author__ = 'kotzilla' |
||||
@ -1,25 +0,0 @@ |
||||
# -*- coding: utf-8 -*- |
||||
import MySQLdb |
||||
from MySQLdb.cursors import DictCursor |
||||
from django.core.management.base import BaseCommand, CommandError |
||||
from country.models import Country |
||||
|
||||
|
||||
class Command(BaseCommand): |
||||
def handle(self, *args, **options): |
||||
# local database(will not work on production) |
||||
db = MySQLdb.connect(host="localhost", |
||||
user="root", |
||||
passwd="qazedc", |
||||
db="test", |
||||
charset='utf8', |
||||
cursorclass=DictCursor) |
||||
cursor = db.cursor() |
||||
# !!!database can change |
||||
sql = "SELECT country_code as code, geo_lat as latitude, geo_lng as longitude FROM test.country_country LEFT JOIN localization.meta_location ON test.country_country.country_code=localization.meta_location.iso COLLATE utf8_unicode_ci WHERE localization.meta_location.type='CO' AND geo_lat IS NOT NULL;" |
||||
cursor.execute(sql) |
||||
result = cursor.fetchall() |
||||
for item in result: |
||||
updates = Country.objects.filter(country_code=item['code']).update(latitude=item['latitude'], longitude=item['longitude']) |
||||
if updates: |
||||
print(item['code']) |
||||
@ -1,39 +0,0 @@ |
||||
# -*- coding: utf-8 -*- |
||||
import MySQLdb |
||||
from MySQLdb.cursors import DictCursor |
||||
from django.core.management.base import BaseCommand, CommandError |
||||
from django.utils import translation |
||||
from country.models import Country |
||||
|
||||
|
||||
def get_from_old(country): |
||||
db = MySQLdb.connect(host="localhost", |
||||
user="kotzilla", |
||||
passwd="qazedc", |
||||
db="test2", |
||||
charset='utf8', |
||||
cursorclass=DictCursor) |
||||
cursor = db.cursor() |
||||
sql = """SELECT url, inflect FROM old_expomap.products_places WHERE title="%(name)s" """%{'name': country.name.encode('utf-8')} |
||||
#print(country.name.encode('utf-8')) |
||||
# print(sql) |
||||
cursor.execute(sql) |
||||
result = cursor.fetchone() |
||||
|
||||
return result |
||||
|
||||
|
||||
class Command(BaseCommand): |
||||
def handle(self, *args, **options): |
||||
translation.activate('ru') |
||||
for country in Country.objects.all(): |
||||
old_data = get_from_old(country) |
||||
if old_data is None: |
||||
continue |
||||
country.old_url = old_data['url'] |
||||
country.inflect = old_data['inflect'] |
||||
try: |
||||
country.save() |
||||
print(country) |
||||
except: |
||||
continue |
||||
Loading…
Reference in new issue