get city not country list

This commit is contained in:
j 2020-05-30 03:13:57 +02:00
commit 5cde8977ef
2 changed files with 13 additions and 7 deletions

View file

@ -17,15 +17,22 @@ def get_location(ip):
country = city = None
try:
g = GeoIP2()
location = g.city(ip)
except:
country = city = None
else:
try:
location = g.city(ip)
except django.contrib.gis.geoip2.GeoIP2Exception:
try:
location = g.country(s.ip)
except:
location = None
if location:
country = ox.get_country_name(location['country_code'])
if location['city']:
if location.get('city'):
city = location['city']
if isinstance(city, bytes):
city = city.decode('latin-1')
except:
country = city = None
return city, country