From b7517bce6521526c2505793234e21e427f7baf91 Mon Sep 17 00:00:00 2001 From: Gregory Danielson Date: Sun, 15 Nov 2020 10:56:43 -0600 Subject: [PATCH] Rework ip2location to include ccode, lat, long for cache purposes --- lib/location.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/location.py b/lib/location.py index 89f66bb..da41dc1 100644 --- a/lib/location.py +++ b/lib/location.py @@ -128,19 +128,18 @@ def ip2location(ip_addr): # if IP2LOCATION_KEY is not set, do not query, # because the query wont be processed anyway if not IP2LOCATION_KEY: - return None, None, None + return None try: r = requests.get( - 'http://api.ip2location.com/?ip=%s&key=%s&package=WS3' + 'http://api.ip2location.com/?ip=%s&key=%s&package=WS5' % (ip_addr, IP2LOCATION_KEY)) r.raise_for_status() location = r.text if location and ';' in location: - _, country, region, city = location.split(';') - location = city, region, country + ccode, country, region, city, lat, long, *_ = location.split(';') except requests.exceptions.RequestException: - return None, None, None - return city, region, country + return None + return city, region, country, ccode, lat, long def ipinfo(ip_addr):