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.
201 lines
7.3 KiB
201 lines
7.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'
|
|
|
|
import datetime
|
|
from theme.models import Theme
|
|
from conference.models import Conference
|
|
'''
|
|
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()
|
|
conf_old = """
|
|
SELECT DISTINCT (products_to_categories.products_id), url as old_url
|
|
FROM `products_to_categories`
|
|
LEFT JOIN `products` ON products_to_categories.products_id=products.products_id
|
|
LEFT JOIN `products_description` ON products_to_categories.products_id=products_description.products_id
|
|
WHERE `products_status` =1
|
|
AND `conference` =0
|
|
|
|
"""
|
|
|
|
|
|
find_themes = "SELECT categories_id FROM `products_to_categories` WHERE `products_id` =%d"
|
|
|
|
cursor.execute(conf_old)
|
|
|
|
conferences = cursor.fetchall()
|
|
#for item in conferences:
|
|
cursor.execute(find_themes%conferences[0]['products_id'])
|
|
|
|
day = datetime.date.today()
|
|
day = day.replace(month=1, day=1)
|
|
|
|
for item in conferences:
|
|
old_url = item['old_url']
|
|
if not old_url:
|
|
continue
|
|
try:
|
|
expo = Exposition.objects.get(old_url=old_url)
|
|
except:
|
|
continue
|
|
if expo.data_begin > day:
|
|
continue
|
|
|
|
cursor.execute(find_themes%item['products_id'])
|
|
|
|
themes_id = [i['categories_id'] for i in cursor.fetchall()]
|
|
theme_qs = Theme.objects.filter(id__in=themes_id)
|
|
|
|
expo.theme.add(*theme_qs)
|
|
print(expo)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if item['categories_id'] == 0:
|
|
# continue
|
|
# Theme.objects.get(id=item['categories_id'])
|
|
#print(result)
|
|
'''
|
|
|
|
from haystack.query import SearchQuerySet
|
|
from django.db import IntegrityError
|
|
from django.utils import translation
|
|
|
|
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
|
|
ORDER BY products.products_id DESC
|
|
"""
|
|
translation.activate('ru')
|
|
expos = list(Exposition.objects.language().filter(old_url=''))
|
|
find_expo = "SELECT products_name, url from products_description WHERE products_name = '%s'"
|
|
|
|
for expo in expos:
|
|
cursor.execute(find_expo%expo.name)
|
|
result = cursor.fetchall()
|
|
if result:
|
|
expo.old_url = result[0]['url']
|
|
expo.save()
|
|
print(expo)
|
|
|
|
#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):
|
|
qs = SearchQuerySet().models(Exposition).filter(name_ru=item['name'])
|
|
if not item:
|
|
continue
|
|
if not qs.count()>0:
|
|
continue
|
|
expo =qs[0].object
|
|
|
|
if not expo or expo.old_url:
|
|
continue
|
|
print(expo)
|
|
expo.old_url = item['old_url']
|
|
try:
|
|
expo.save()
|
|
except IntegrityError:
|
|
continue
|
|
|
|
|
|
"""
|
|
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
|
|
"""
|
|
'''
|
|
|