fix get_ruby_data

This commit is contained in:
Anatoly 2019-12-12 17:15:08 +03:00
parent 5fe8273379
commit 8ca8c73b4b

View File

@ -1,23 +1,22 @@
from transfer.serializers import location as location_serializers
from transfer import models as transfer_models
from location.models import Country, Region, City, Address, CityGallery
import csv
import json
from django.db.transaction import atomic
from gallery.models import Image
from pprint import pprint
from django.conf import settings
from collection.models import Collection
from django.db.transaction import atomic
from requests import get
from main.models import AwardType
from tqdm import tqdm
from account.models import Role
from collection.models import Collection
from gallery.models import Image
from location.models import Country, Region, City, Address, CityGallery
from main.models import AwardType
from news.models import News
from review.models import Review
from tag.models import TagCategory, ChosenTagSettings
import csv
from transfer import models as transfer_models
from transfer.serializers import location as location_serializers
from transfer.utils import clean_old_records
@ -285,10 +284,11 @@ def get_ruby_data():
error_file.write(f"{json.dumps(ruby_params)}: {json.dumps(ruby_response)}\n")
continue
city_name = mysql_city.name.strip()
ruby_data[mysql_city.id] = {
"mysql_id": mysql_city.id,
"name": mysql_city.name,
"name_translated": '{"en-GB":"' + mysql_city.name + '"}',
"name": city_name,
"name_translated": {'en-GB': city_name},
"map1": mysql_city.map1,
"map2": mysql_city.map2,
@ -318,7 +318,7 @@ def get_ruby_data():
# Add correct objects of Country, Region and City with mysql_ids array (Country, Region) and mysql_id (City)
def add_correct_location_models(ruby_data):
for mysql_id, city_object in ruby_data.items():
for mysql_id, city_object in tqdm(ruby_data.items()):
country_data = city_object["country"]
try:
country = Country.objects.get(code=country_data['code'], mysql_ids__isnull=False)
@ -345,7 +345,8 @@ def add_correct_location_models(ruby_data):
subregion_data = city_object.pop('subregion')
subregion_data['country'] = country
try:
subregion = Region.objects.get(code=subregion_data['code'], mysql_ids__isnull=False)
subregion = Region.objects.get(code=subregion_data['code'],
mysql_ids__isnull=False)
subregion.mysql_ids.append(mysql_id)
subregion.save()
except Region.DoesNotExist:
@ -491,22 +492,22 @@ def fix_location_models():
print('add_correct_location_models')
add_correct_location_models(ruby_data)
print('fix_location_address')
fix_location_address()
print('fix_location_collection')
fix_location_collection()
print('fix_award_type')
fix_award_type()
print('fix_role')
fix_role()
print('fix_news')
fix_news()
print('fix_reviews')
fix_reviews()
print('fix_tag_category')
fix_tag_category()
print('fix_chosen_tag')
fix_chosen_tag()
# print('fix_location_address')
# fix_location_address()
# print('fix_location_collection')
# fix_location_collection()
# print('fix_award_type')
# fix_award_type()
# print('fix_role')
# fix_role()
# print('fix_news')
# fix_news()
# print('fix_reviews')
# fix_reviews()
# print('fix_tag_category')
# fix_tag_category()
# print('fix_chosen_tag')
# fix_chosen_tag()
def remove_old_records():