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.
68 lines
2.2 KiB
68 lines
2.2 KiB
# -*- coding: utf-8 -*-
|
|
import xlrd
|
|
import urllib2
|
|
from django.core.management.base import BaseCommand
|
|
from django.conf import settings
|
|
from functions.form_check import translit_with_separator
|
|
from functions.files import get_alternative_filename
|
|
from exposition.models import Exposition, Statistic
|
|
from organiser.models import Organiser
|
|
|
|
|
|
CHINA_FILE = settings.MEDIA_ROOT+'/import/expo_china_ru.xlsx'
|
|
GERMANY_FILE = settings.MEDIA_ROOT+'/import/expo_germany_ru.xlsx'
|
|
# 391 row not imported(same url)
|
|
ITALY_FILE = settings.MEDIA_ROOT+'/import/expo_italy_ru.xlsx'
|
|
# moscow 3 exps
|
|
F = settings.MEDIA_ROOT+'/import/exp.xlsx'
|
|
|
|
LA_FILE = settings.MEDIA_ROOT+'/import/expo_la.xlsx'
|
|
NA_EU_ASIA_FILE = settings.MEDIA_ROOT+'/import/expo_na_eu_ sa.xls'
|
|
NA_EU_ASIA_FILE2 = settings.MEDIA_ROOT+'/import/expo_na_eu_ sa_part2.xls'
|
|
RUSSIA_FILE = settings.MEDIA_ROOT+'/import/expo_russia.xls'
|
|
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
|
|
f = open(RUSSIA_FILE, 'r')
|
|
book = xlrd.open_workbook(file_contents=f.read())
|
|
sheet = book.sheet_by_index(0)
|
|
row_list = [sheet.row_values(row_number) for row_number in range(sheet.nrows)]
|
|
labels = [label for label in row_list[0]]
|
|
|
|
for row_number, row in enumerate(row_list[1:]):
|
|
exp_url = translit_with_separator(row[2])
|
|
try:
|
|
exp = Exposition.objects.language('ru').get(url=exp_url)
|
|
except Exposition.DoesNotExist:
|
|
continue
|
|
if not row[30]:
|
|
continue
|
|
|
|
year = int(row[30])
|
|
|
|
|
|
try:
|
|
countries_number = int(exp.stat_countries)
|
|
countries = ''
|
|
except ValueError:
|
|
countries_number = None
|
|
countries = exp.stat_countries
|
|
|
|
members = exp.members
|
|
visitors = exp.visitors
|
|
area = exp.area
|
|
|
|
|
|
s = Statistic(exposition=exp,
|
|
year=year,
|
|
countries_number=countries_number,
|
|
members=members,
|
|
visitors=visitors,
|
|
area=area)
|
|
s.translate('ru')
|
|
s.countries = countries
|
|
s.save()
|
|
|
|
print(exp)
|
|
|