Do cache read and write in get_location instead of duplicated in each IPLOCATION_ORDER method

gregdan3/master
Gregory Danielson 4 years ago
parent 7af4aaa8ec
commit e4ac3f266f
No known key found for this signature in database
GPG Key ID: 88D4EF22F6C14CA7

@ -187,6 +187,10 @@ def get_location(ip_addr):
"""
Return location triple (CITY, REGION, COUNTRY) for `ip_addr`
"""
location = ipcache(ip_addr)
if location:
return location
for method in IPLOCATION_ORDER:
if method == 'geoip':
city, region, country = geoip(ip_addr)
@ -195,10 +199,13 @@ def get_location(ip_addr):
elif method == 'ipinfo':
city, region, country = ipinfo(ip_addr)
else:
print("ERROR: invalid iplocation method speficied: %s" % method)
if city is not None:
city, region, country = workaround(city, region, country)
return city, region, country
print("ERROR: invalid iplocation method specified: %s" % method)
if all((city, region, country)):
ipcachewrite(ip_addr, (city, region, country))
# cache write used to happen before workaround, preserve that
city, region, country = workaround(city, region, country)
return city, region, country
#
# temporary disabled it because of geoip services capcacity
#

Loading…
Cancel
Save