Skip to content

Commit

Permalink
Update av_result_parser.py
Browse files Browse the repository at this point in the history
Fixed crash where no lat/lng returned
  • Loading branch information
henrikvalv3 committed Feb 3, 2023
1 parent 1e1aca8 commit aedb9f3
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/av_result_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,26 @@ def get_latlong(address_validation_result):
Returns:
_type_: _description_
"""
try:
try:
latlong_dict={}

if LOCATION in address_validation_result[RESULT][GEOCODE]:
if LATITUDE in address_validation_result[RESULT][GEOCODE][LOCATION]:
latlong_dict[LATITUDE] = address_validation_result[RESULT][GEOCODE][LOCATION][LATITUDE]

#Get the longitude from geocode
if LONGITUDE in address_validation_result[RESULT][GEOCODE][LOCATION]:
latlong_dict[LONGITUDE] = address_validation_result[RESULT][GEOCODE][LOCATION][LONGITUDE]
#Init the Lat/Lng values as zero to handle cases where the API doesn't return a result.
latlong_dict[LATITUDE] = 0
latlong_dict[LONGITUDE] = 0
if GEOCODE in address_validation_result[RESULT]:
if LOCATION in address_validation_result[RESULT][GEOCODE]:
if LATITUDE in address_validation_result[RESULT][GEOCODE][LOCATION]:
latlong_dict[LATITUDE] = address_validation_result[RESULT][GEOCODE][LOCATION][LATITUDE]

#Get the longitude from geocode
if LONGITUDE in address_validation_result[RESULT][GEOCODE][LOCATION]:
latlong_dict[LONGITUDE] = address_validation_result[RESULT][GEOCODE][LOCATION][LONGITUDE]
return latlong_dict
except Exception as err:
print(f"Unexpected {err=}, {type(err)=}")
print("No latitude or longitude found")
print("Error getting latitude or longitude")
raise


def get_postal_address(address_validation_result):
"""_summary_: Get the detailed postal address fromt the Address Validation result
Expand Down Expand Up @@ -332,7 +336,7 @@ def get_usps_data(address_validation_result):

print("uspsData extracted from result is:")
print(usps_data)
return usps_data
return usps_data

except Exception as err:
print(f"Unexpected {err=}, {type(err)=}")
Expand Down

0 comments on commit aedb9f3

Please sign in to comment.