Skip to content

Commit

Permalink
Fix downloading GeoIP database
Browse files Browse the repository at this point in the history
  • Loading branch information
caryoscelus committed Jul 29, 2023
1 parent 714729e commit e79924d
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions plugins/Sidebar/SidebarPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def actionSidebarGetHtmlTag(self, to):
def downloadGeoLiteDb(self, db_path):
import gzip
import shutil
from util import helper
import requests

if config.offline or config.tor == 'always':
return False
Expand All @@ -617,19 +617,18 @@ def downloadGeoLiteDb(self, db_path):
downloadl_err = None
try:
# Download
response = helper.httpRequest(db_url)
data_size = response.getheader('content-length')
response = requests.get(db_url, stream=True)
data_size = response.headers.get('content-length')
if data_size is None:
data.write(response.content)
data_size = int(data_size)
data_recv = 0
data = io.BytesIO()
while True:
buff = response.read(1024 * 512)
if not buff:
break
for buff in response.iter_content(chunk_size=1024 * 512):
data.write(buff)
data_recv += 1024 * 512
if data_size:
progress = int(float(data_recv) / int(data_size) * 100)
self.cmd("progress", ["geolite-info", _["Downloading GeoLite2 City database (one time only, ~20MB)..."], progress])
progress = int(float(data_recv) / data_size * 100)
self.cmd("progress", ["geolite-info", _["Downloading GeoLite2 City database (one time only, ~20MB)..."], progress])
self.log.info("GeoLite2 City database downloaded (%s bytes), unpacking..." % data.tell())
data.seek(0)

Expand Down

0 comments on commit e79924d

Please sign in to comment.