This commit is contained in:
j 2021-10-27 16:19:55 +01:00
commit 6f7053ed03
8 changed files with 81 additions and 7 deletions

View file

@ -0,0 +1,29 @@
import os
import re
import ox
from django.core.management.base import BaseCommand
from django.conf import settings
class Command(BaseCommand):
"""
"""
help = 'update geoip database'
args = ''
def handle(self, **options):
force = False
path = settings.GEOIP_PATH / 'GeoLite2-City.mmdb'
index = ox.net.read_url('https://db-ip.com/db/download/ip-to-city-lite').decode()
match = re.compile('href=[\'"](http.*.mmdb.gz)').findall(index)
if match:
url = match[0]
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)
else:
print('failed to download GeoLite2-City.mmdb')