From 4cce468daea267e192bbd3cbfc97b26a0f4e7b1c Mon Sep 17 00:00:00 2001 From: j Date: Sun, 22 Mar 2020 17:21:57 +0100 Subject: [PATCH] dbip-city-lite url changes, get latest url from download page --- pandora/app/config.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pandora/app/config.py b/pandora/app/config.py index db5a1bac..db407178 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: