use geoip2 api to fix ipv6 lookups

This commit is contained in:
j 2016-03-04 12:50:44 +05:30
commit 4613005b83
4 changed files with 13 additions and 13 deletions

View file

@ -308,17 +308,9 @@ def update_static():
os.symlink(default_script, script)
def update_geoip(force=False):
path = os.path.join(settings.GEOIP_PATH, 'GeoLiteCity.dat')
path = os.path.join(settings.GEOIP_PATH, 'GeoLite2-City.mmdb')
if not os.path.exists(path) or force:
url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz'
print('download', url)
ox.net.save_url(url, "%s.gz"%path)
if os.path.exists(path):
os.unlink(path)
os.system('gunzip "%s.gz"' % path)
path = os.path.join(settings.GEOIP_PATH, 'GeoLiteCityv6.dat')
if not os.path.exists(path) or force:
url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz'
url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz'
print('download', url)
ox.net.save_url(url, "%s.gz"%path)
if os.path.exists(path):

View file

@ -7,7 +7,8 @@ from django.contrib.auth.models import User, Group
from django.db import models
from django.db.models import Max
from django.conf import settings
from django.contrib.gis.geoip import GeoIP
from django.contrib.gis.geoip2 import GeoIP2
import ox
@ -66,7 +67,7 @@ class SessionData(models.Model):
self.parse_useragent()
if self.ip:
try:
g = GeoIP()
g = GeoIP2()
location = g.city(self.ip)
if location:
country = ox.get_country_name(location['country_code'])