From 74f9cfa29b453eec30c2f4aeaebd0aac4c7a17d5 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Mon, 7 May 2018 15:35:07 +0900 Subject: [PATCH] Write non Latin geolocation data if only non latin one is found In case only non Latin geo location data is found, the first match will be used to replace the not found Latin entry --- bin/reverse_geolocate.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/reverse_geolocate.py b/bin/reverse_geolocate.py index fd77ed1..9d1873d 100755 --- a/bin/reverse_geolocate.py +++ b/bin/reverse_geolocate.py @@ -190,6 +190,7 @@ def reverseGeolocateOpenStreetMap(longitude, latitude): def reverseGeolocateGoogle(longitude, latitude): # init geolocation = reverseGeolocateInit(longitude, latitude) + temp_geolocation = geolocation.copy() if geolocation['status'] == 'ERROR': return geolocation # sensor (why?) @@ -250,15 +251,24 @@ def reverseGeolocateGoogle(longitude, latitude): # this is an array, so we need to loop through each for addr in entry['address_components']: # in types check that index is in there and the location is not yet set - # also check that entry is NOT in japanese + # also check that entry is in LATIN based + # NOTE: fallback if all are non LATIN? if index in addr['types'] and not geolocation[loc_index]: # for country code we need to use short name, else we use long name if loc_index == 'CountryCode': if onlyLatinChars(addr['short_name']): geolocation[loc_index] = addr['short_name'] + elif not temp_geolocation[loc_index]: + temp_geolocation[loc_index] = addr['short_name'] else: if onlyLatinChars(addr['long_name']): geolocation[loc_index] = addr['long_name'] + elif not temp_geolocation[loc_index]: + temp_geolocation[loc_index] = addr['long_name'] + # check that all in geoloaction are filled and if not fille from temp_geolocation dictionary + for loc_index in type_map: + if not geolocation[loc_index] and temp_geolocation[loc_index]: + geolocation[loc_index] = temp_geolocation[loc_index] # write OK status geolocation['status'] = response.json()['status'] else: