17.12
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
This module houses the GeoIP2 object, a wrapper for the MaxMind GeoIP2(R)
|
||||
Python API (https://geoip2.readthedocs.io/). This is an alternative to the
|
||||
Python GeoIP2 interface provided by MaxMind.
|
||||
|
||||
GeoIP(R) is a registered trademark of MaxMind, Inc.
|
||||
|
||||
For IP-based geolocation, this module requires the GeoLite2 Country and City
|
||||
datasets, in binary format (CSV will not work!). The datasets may be
|
||||
downloaded from MaxMind at http://dev.maxmind.com/geoip/geoip2/geolite2/.
|
||||
Grab GeoLite2-Country.mmdb.gz and GeoLite2-City.mmdb.gz, and unzip them in the
|
||||
directory corresponding to settings.GEOIP_PATH.
|
||||
"""
|
||||
__all__ = ['HAS_GEOIP2']
|
||||
|
||||
try:
|
||||
import geoip2 # NOQA
|
||||
except ImportError:
|
||||
HAS_GEOIP2 = False
|
||||
else:
|
||||
from .base import GeoIP2, GeoIP2Exception
|
||||
HAS_GEOIP2 = True
|
||||
__all__ += ['GeoIP2', 'GeoIP2Exception']
|
||||
@@ -0,0 +1,21 @@
|
||||
def City(response):
|
||||
return {
|
||||
'city': response.city.name,
|
||||
'continent_code': response.continent.code,
|
||||
'continent_name': response.continent.name,
|
||||
'country_code': response.country.iso_code,
|
||||
'country_name': response.country.name,
|
||||
'dma_code': response.location.metro_code,
|
||||
'latitude': response.location.latitude,
|
||||
'longitude': response.location.longitude,
|
||||
'postal_code': response.postal.code,
|
||||
'region': response.subdivisions[0].iso_code if response.subdivisions else None,
|
||||
'time_zone': response.location.time_zone,
|
||||
}
|
||||
|
||||
|
||||
def Country(response):
|
||||
return {
|
||||
'country_code': response.country.iso_code,
|
||||
'country_name': response.country.name,
|
||||
}
|
||||
Reference in New Issue
Block a user