mirror of
https://gitea.com/bipinkrish/DeGourou.git
synced 2024-11-17 09:50:21 +00:00
Added progress bar
This commit is contained in:
parent
b609d6f0e6
commit
b6a000b7b9
1 changed files with 12 additions and 0 deletions
|
@ -257,13 +257,25 @@ def sendHTTPRequest_DL2FILE(URL, outputfile):
|
||||||
if ret_code != 200:
|
if ret_code != 200:
|
||||||
return ret_code
|
return ret_code
|
||||||
|
|
||||||
|
total_size = int(handler.headers.get("Content-Length", 0))
|
||||||
|
bytes_so_far = 0
|
||||||
|
|
||||||
|
print()
|
||||||
with open(outputfile, "wb") as f:
|
with open(outputfile, "wb") as f:
|
||||||
while True:
|
while True:
|
||||||
chunk = handler.read(chunksize)
|
chunk = handler.read(chunksize)
|
||||||
if not chunk:
|
if not chunk:
|
||||||
break
|
break
|
||||||
|
bytes_so_far += len(chunk)
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
|
|
||||||
|
# progress bar
|
||||||
|
progress = float(bytes_so_far) / total_size
|
||||||
|
progress_bar_width = 40
|
||||||
|
progress_bar = ('[' + '=' * int(progress * progress_bar_width)).ljust(progress_bar_width + 1) + ']'
|
||||||
|
percent = round(progress * 100, 2)
|
||||||
|
print("Downloaded %d of %d bytes %s %0.2f%%" % (bytes_so_far, total_size, progress_bar, percent), end='\r')
|
||||||
|
|
||||||
return 200
|
return 200
|
||||||
|
|
||||||
def sendHTTPRequest_getSimple(URL):
|
def sendHTTPRequest_getSimple(URL):
|
||||||
|
|
Loading…
Reference in a new issue