You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
4.3 KiB
103 lines
4.3 KiB
# -*- coding: utf-8 -*-
|
|
import os
|
|
import MySQLdb
|
|
from MySQLdb.cursors import DictCursor
|
|
from django.core.management.base import BaseCommand
|
|
from django.conf import settings
|
|
from exposition.models import Exposition
|
|
from conference.management.commands.conf_old import filter_city, filter_country, get_periodic, get_logo, get_places
|
|
from django.core.files import File
|
|
from functions.translate import fill_with_signal
|
|
from country.models import Country
|
|
from city.models import City
|
|
|
|
file_path = settings.MEDIA_ROOT + 'exposition/bad_expos.txt'
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
db = MySQLdb.connect(host="localhost",
|
|
user="expomap",
|
|
passwd="7FbLtAGjse",
|
|
db="old_db",
|
|
charset='utf8',
|
|
cursorclass=DictCursor)
|
|
cursor = db.cursor()
|
|
sql = """
|
|
SELECT products.products_id as id, products_date_added as created, products_last_modified as modified,
|
|
discount, expohit, ufi, products_name as name, products_description as description,
|
|
products_short_description as main_title, products_viewed as viewed, products_period as period,
|
|
products_org as organiser,products_products as products, products_official as web_page,
|
|
products_img1 as logo, products_startdate as data_begin, products_enddate as data_end,
|
|
url as old_url, places_id
|
|
FROM `products`
|
|
LEFT JOIN `products_description` ON products.products_id=products_description.products_id
|
|
WHERE `products_status` =1
|
|
AND `conference` =0 AND places_id >0
|
|
"""
|
|
|
|
cursor.execute(sql)
|
|
result = cursor.fetchall()
|
|
|
|
names = [item['name'] for item in result]
|
|
#media = settings.MEDIA_ROOT.replace('media/', '')
|
|
#counter = 0
|
|
#bad_cities = {}
|
|
|
|
bad_expos = []
|
|
for i, item in enumerate(result):
|
|
|
|
print('number: %d, errors: %d'%(i, len(bad_expos)))
|
|
name = item['name']
|
|
if Exposition.objects.filter(translations__name=name).exists():
|
|
msg = u'%s|||%s|||%s'%(name, item['old_url'], 'already exist')
|
|
bad_expos.append(msg)
|
|
continue
|
|
|
|
data_begin = item['data_begin']
|
|
data_end= item['data_end']
|
|
|
|
|
|
place_id = item['places_id'] # convert to country and city
|
|
country, city = get_places(place_id)
|
|
|
|
if not country or not city:
|
|
msg = u'%s|||%s|||%s'%(name, item['old_url'], 'bad country or city')
|
|
bad_expos.append(msg)
|
|
continue
|
|
old_url = item['old_url']
|
|
periodic = item['period']
|
|
periodic = get_periodic(periodic)
|
|
web_page = item['web_page']
|
|
currency = 'USD'
|
|
expohit = item['expohit']
|
|
ufi = item['ufi']
|
|
if ufi:
|
|
ufi = 1
|
|
else:
|
|
ufi = 0
|
|
|
|
created = item['created']
|
|
modified = item['modified']
|
|
|
|
data = {'name_ru': name, 'main_title_ru': item['main_title'], 'description_ru': item['description'],
|
|
'products_ru': item['products'], 'discount_description_ru': '', 'time_ru': '', 'price_day_ru':'',
|
|
'price_all_ru': '', 'price_day_bar_ru': '', 'price_all_bar_ru': '', 'stat_countries_ru': '',
|
|
'pre_condition_ru':'', 'stand_condition_ru': '', 'visit_note_ru': '', 'participation_note_ru': '',
|
|
'title_ru': '', 'descriptions_ru': '', 'keywords_ru': ''}
|
|
|
|
exposition = Exposition(data_begin=data_begin, data_end=data_end, city=city, country=country,
|
|
web_page=web_page, old_url=old_url, periodic=periodic, currency=currency,
|
|
expohit=expohit, created=created, modified=modified, quality_label=ufi)
|
|
|
|
try:
|
|
fill_with_signal(Exposition, exposition, data)
|
|
except Exception as e:
|
|
msg = u'%s|||%s|||%s'%(name, item['old_url'], str(e))
|
|
bad_expos.append(msg)
|
|
continue
|
|
|
|
print('saving file')
|
|
file = open(file_path, 'w')
|
|
for item in bad_expos:
|
|
file.write("%s\n" % item)
|
|
file.close() |