pdnew/geoip.py

22 lines
365 B
Python

import geoip2.errors
import geoip2.database
from application import app
def lookup_city(addr):
try:
with geoip2.database.Reader(app.config['GEOIP2_DATABASE']) as reader:
return reader.city(addr)
except geoip2.errors.AddressNotFoundError:
pass
except Exception:
if app.debug:
raise
return None