dbip-city-lite url changes, get latest url from download page

This commit is contained in:
j 2020-03-22 17:21:57 +01:00
parent 6f4bdebd88
commit 4cce468dae

View file

@ -1,12 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import from __future__ import division, print_function, absolute_import
import codecs
import os import os
import sys import re
import shutil import shutil
import subprocess import subprocess
import sys
import time import time
import codecs
from os.path import dirname, exists, join from os.path import dirname, exists, join
from glob import glob from glob import glob
@ -399,12 +400,18 @@ def update_geoip(force=False):
path = os.path.join(settings.GEOIP_PATH, 'GeoLite2-City.mmdb') path = os.path.join(settings.GEOIP_PATH, 'GeoLite2-City.mmdb')
if not os.path.exists(path) or force: if not os.path.exists(path) or force:
url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz' 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' index = ox.net.read_url('https://db-ip.com/db/download/ip-to-country-lite').decode()
print('download', url) match = re.compile('href=[\'"](http.*.mmdb.gz)').findall(index)
ox.net.save_url(url, "%s.gz" % path) if match:
if os.path.exists(path): url = match[0]
os.unlink(path) print(url)
os.system('gunzip "%s.gz"' % path) 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(): def init():
if not settings.RELOADER_RUNNING: if not settings.RELOADER_RUNNING: