use cdn
This commit is contained in:
parent
9ffb421ba3
commit
6f7053ed03
8 changed files with 81 additions and 7 deletions
29
app/video/management/commands/update_geoip.py
Normal file
29
app/video/management/commands/update_geoip.py
Normal 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')
|
||||
Loading…
Add table
Add a link
Reference in a new issue