|
|
@ -22,6 +22,8 @@ from globals import GEOLITE, GEOLOCATOR_SERVICE, IP2LCACHE, IP2LOCATION_KEY, NOT
|
|
|
|
|
|
|
|
|
|
|
|
GEOIP_READER = geoip2.database.Reader(GEOLITE)
|
|
|
|
GEOIP_READER = geoip2.database.Reader(GEOLITE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
COUNTRY_MAP = {"Russian Federation": "Russia"}
|
|
|
|
|
|
|
|
|
|
|
|
def ascii_only(string):
|
|
|
|
def ascii_only(string):
|
|
|
|
"Check if `string` contains only ASCII symbols"
|
|
|
|
"Check if `string` contains only ASCII symbols"
|
|
|
|
|
|
|
|
|
|
|
@ -165,15 +167,11 @@ def geoip(ip_addr):
|
|
|
|
return None, None, None
|
|
|
|
return None, None, None
|
|
|
|
return city, region, country
|
|
|
|
return city, region, country
|
|
|
|
|
|
|
|
|
|
|
|
def workaround(city, region, country):
|
|
|
|
def workaround(country):
|
|
|
|
# workaround for the strange bug with the country name
|
|
|
|
# workaround for strange bug with the country name
|
|
|
|
# maybe some other countries has this problem too
|
|
|
|
# maybe some other countries has this problem too
|
|
|
|
#
|
|
|
|
country = COUNTRY_MAP.get(country) or country
|
|
|
|
# Having these in a separate function will help if this gets to
|
|
|
|
return country
|
|
|
|
# be a problem
|
|
|
|
|
|
|
|
if country == 'Russian Federation':
|
|
|
|
|
|
|
|
country = 'Russia'
|
|
|
|
|
|
|
|
return city, region, country
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_location(ip_addr):
|
|
|
|
def get_location(ip_addr):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|