Be certain data is present in the response

This commit is contained in:
Parker M. 2024-11-03 23:05:03 -06:00
parent 179c29b279
commit 65fef62741
Signed by: parker
GPG Key ID: 505ED36FC12B5D5E

View File

@ -32,7 +32,17 @@ def ip_to_location(ip):
)
return "-, -", "-"
location = f'{data["country_name"]}, {data["city_name"]}'
location = ""
# Sometimes a certain name may not be present, so always check
if "city_name" in data:
location += data["city_name"]
if "region_name" in data:
location += f', {data["region_name"]}'
if "country_name" in data:
location += f', {data["country_name"]}'
isp = data["as"]
return location, isp