diff --git a/pandora/app/config.py b/pandora/app/config.py index db5a1bac5..db4071784 100644 --- a/pandora/app/config.py +++ b/pandora/app/config.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- from __future__ import division, print_function, absolute_import +import codecs import os -import sys +import re import shutil import subprocess +import sys import time -import codecs from os.path import dirname, exists, join from glob import glob @@ -399,12 +400,18 @@ def update_geoip(force=False): 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/GeoLite2-City.mmdb.gz' - url = 'https://download.db-ip.com/free/dbip-city-lite-2020-01.mmdb.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) + index = ox.net.read_url('https://db-ip.com/db/download/ip-to-country-lite').decode() + match = re.compile('href=[\'"](http.*.mmdb.gz)').findall(index) + if match: + url = match[0] + print(url) + 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 dbip-country-lite-2020-03.mmdb.gz') def init(): if not settings.RELOADER_RUNNING: