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
|
||||
# Utils functions defined before transfer functions
|
||||
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)
|
||||
try:
|
||||
data = json.loads(response.text)
|
||||
|
|
@ -255,16 +255,16 @@ def get_ruby_socket(params):
|
|||
# Get data from ruby and save it to file
|
||||
# Save errors from ruby to another file
|
||||
def get_ruby_data():
|
||||
cities = City.objects.filter(old_id__isnull=False)
|
||||
cities = transfer_models.Cities.objects.all()
|
||||
ruby_data = {}
|
||||
error_file = open(f"{settings.PROJECT_ROOT}/ruby_error.txt", "w")
|
||||
|
||||
for city in cities:
|
||||
try:
|
||||
mysql_city = transfer_models.Cities.objects.get(id=city.old_id)
|
||||
except transfer_models.Cities.DoesNotExist:
|
||||
print(f"City with id {city.old_id} not found")
|
||||
continue
|
||||
for mysql_city in cities:
|
||||
# try:
|
||||
# mysql_city = transfer_models.Cities.objects.get(id=city.old_id)
|
||||
# except transfer_models.Cities.DoesNotExist:
|
||||
# print(f"City with id {city.old_id} not found")
|
||||
# continue
|
||||
|
||||
ruby_params = {}
|
||||
|
||||
|
|
@ -289,11 +289,15 @@ def get_ruby_data():
|
|||
error_file.write(f"{json.dumps(ruby_params)}: {json.dumps(ruby_response)}\n")
|
||||
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()
|
||||
ruby_data[mysql_city.id] = {
|
||||
"mysql_id": mysql_city.id,
|
||||
"name": city_name,
|
||||
"name_translated": {'en-GB': city_name},
|
||||
"name": city_name.strip(),
|
||||
"name_translated": {'en-GB': city_name.strip()},
|
||||
|
||||
"map1": mysql_city.map1,
|
||||
"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,
|
||||
|
||||
"postal_code": mysql_city.zip_code if mysql_city.zip_code is not None else '',
|
||||
"code": mysql_city.country_code_2.lower()
|
||||
"postal_code": mysql_city.zip_code.strip() if mysql_city.zip_code is not None else '',
|
||||
"code": mysql_city.country_code_2.lower().strip()
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user