mirror of
https://github.com/chubin/wttr.in.git
synced 2025-08-18 01:20:21 +02:00
Remove cache operation from geoip; shortcut where possible
This commit is contained in:
@@ -160,18 +160,12 @@ def ipinfo(ip_addr):
|
|||||||
|
|
||||||
|
|
||||||
def geoip(ip_addr):
|
def geoip(ip_addr):
|
||||||
location = ipcache(ip_addr)
|
|
||||||
if location:
|
|
||||||
return location
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = GEOIP_READER.city(ip_addr)
|
response = GEOIP_READER.city(ip_addr)
|
||||||
location = response.city.name, response.subdivisions.name, response.country.name
|
city, region, country = response.city.name, response.subdivisions.name, response.country.name
|
||||||
except geoip2.errors.AddressNotFoundError:
|
except geoip2.errors.AddressNotFoundError:
|
||||||
location = None, None, None
|
return None, None, None
|
||||||
if location:
|
return city, region, country
|
||||||
ipcachewrite(ip_addr, location)
|
|
||||||
return location
|
|
||||||
|
|
||||||
def workaround(city, region, country):
|
def workaround(city, region, country):
|
||||||
# workaround for the strange bug with the country name
|
# workaround for the strange bug with the country name
|
||||||
|
Reference in New Issue
Block a user