Fix ruby_data
This commit is contained in:
parent
eb514c0ce2
commit
ade2d03402
File diff suppressed because one or more lines are too long
|
|
@ -242,7 +242,7 @@ def migrate_city_photos():
|
||||||
# Update location models with ruby library
|
# Update location models with ruby library
|
||||||
# Utils functions defined before transfer functions
|
# Utils functions defined before transfer functions
|
||||||
def get_ruby_socket(params):
|
def get_ruby_socket(params):
|
||||||
url = 'http://172.21.0.1:5678' # docker host
|
url = 'http://172.26.0.1:5678' # docker host
|
||||||
response = get(url, params=params)
|
response = get(url, params=params)
|
||||||
try:
|
try:
|
||||||
data = json.loads(response.text)
|
data = json.loads(response.text)
|
||||||
|
|
@ -255,16 +255,16 @@ def get_ruby_socket(params):
|
||||||
# Get data from ruby and save it to file
|
# Get data from ruby and save it to file
|
||||||
# Save errors from ruby to another file
|
# Save errors from ruby to another file
|
||||||
def get_ruby_data():
|
def get_ruby_data():
|
||||||
cities = City.objects.filter(old_id__isnull=False)
|
cities = transfer_models.Cities.objects.all()
|
||||||
ruby_data = {}
|
ruby_data = {}
|
||||||
error_file = open(f"{settings.PROJECT_ROOT}/ruby_error.txt", "w")
|
error_file = open(f"{settings.PROJECT_ROOT}/ruby_error.txt", "w")
|
||||||
|
|
||||||
for city in cities:
|
for mysql_city in cities:
|
||||||
try:
|
# try:
|
||||||
mysql_city = transfer_models.Cities.objects.get(id=city.old_id)
|
# mysql_city = transfer_models.Cities.objects.get(id=city.old_id)
|
||||||
except transfer_models.Cities.DoesNotExist:
|
# except transfer_models.Cities.DoesNotExist:
|
||||||
print(f"City with id {city.old_id} not found")
|
# print(f"City with id {city.old_id} not found")
|
||||||
continue
|
# continue
|
||||||
|
|
||||||
ruby_params = {}
|
ruby_params = {}
|
||||||
|
|
||||||
|
|
@ -289,11 +289,15 @@ def get_ruby_data():
|
||||||
error_file.write(f"{json.dumps(ruby_params)}: {json.dumps(ruby_response)}\n")
|
error_file.write(f"{json.dumps(ruby_params)}: {json.dumps(ruby_response)}\n")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if mysql_city.country_code_2 is None:
|
||||||
|
error_file.write(f"{json.dumps(ruby_params)}: {json.dumps(ruby_response)}\n")
|
||||||
|
continue
|
||||||
|
|
||||||
city_name = mysql_city.name.strip()
|
city_name = mysql_city.name.strip()
|
||||||
ruby_data[mysql_city.id] = {
|
ruby_data[mysql_city.id] = {
|
||||||
"mysql_id": mysql_city.id,
|
"mysql_id": mysql_city.id,
|
||||||
"name": city_name,
|
"name": city_name.strip(),
|
||||||
"name_translated": {'en-GB': city_name},
|
"name_translated": {'en-GB': city_name.strip()},
|
||||||
|
|
||||||
"map1": mysql_city.map1,
|
"map1": mysql_city.map1,
|
||||||
"map2": mysql_city.map2,
|
"map2": mysql_city.map2,
|
||||||
|
|
@ -302,8 +306,8 @@ def get_ruby_data():
|
||||||
|
|
||||||
"is_island": True if mysql_city.is_island is not None and mysql_city.is_island > 0 else False,
|
"is_island": True if mysql_city.is_island is not None and mysql_city.is_island > 0 else False,
|
||||||
|
|
||||||
"postal_code": mysql_city.zip_code if mysql_city.zip_code is not None else '',
|
"postal_code": mysql_city.zip_code.strip() if mysql_city.zip_code is not None else '',
|
||||||
"code": mysql_city.country_code_2.lower()
|
"code": mysql_city.country_code_2.lower().strip()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user