Coalesce location into 3-tuple in geoip lookup

This commit is contained in:
Gregory Danielson 2020-11-01 13:45:08 -06:00
parent 4996c5a553
commit ef477822ae
No known key found for this signature in database
GPG key ID: 88D4EF22F6C14CA7

View file

@ -165,14 +165,12 @@ def geoip(ip_addr):
try:
response = GEOIP_READER.city(ip_addr)
country = response.country.name
region = response.subdivisions.name
city = response.city.name
location = response.city.name, response.subdivisions.name, response.country.name
except geoip2.errors.AddressNotFoundError:
country = None
location = None, None, None
region = None
city = None
return city, region, country
return location
def workaround(city, region, country):
# workaround for the strange bug with the country name