Skip to content

Commit

Permalink
added progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
DE0CH committed Jun 16, 2020
1 parent 4ee6b11 commit d2f4011
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
22 changes: 13 additions & 9 deletions download_manager_v2.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import requests
from os import path
import boto3
import sys
import progressbar
if __name__ == '__main__':
with open('archive_links.txt') as links_f:
for url in links_f:
url = url.strip()
url = 'https://file-examples.com/wp-content/uploads/2019/09/file-sample_300kB.rtf'
if not url:
continue
f_name = url.rsplit('/', 1)[-1]
Expand All @@ -15,17 +16,20 @@
# below is downloading content

with open(f_path, 'wb') as f:
response = requests.get(url, allow_redirects=True)
response = requests.get(url, allow_redirects=True, stream=True)
total_length = response.headers.get('content-length')

if total_length is None: # no content length header
f.write(response.content)
else:
dl = 0
total_length = int(total_length)
for data in response.iter_content(chunk_size=4096):
dl += len(data)
f.write(data)
done = int(50 * dl / total_length)
sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50 - done)))
sys.stdout.flush()
with progressbar.ProgressBar(max_value=total_length) as bar:
dl = 0
for data in response.iter_content(chunk_size=4096):
dl += len(data)
f.write(data)
# noinspection PyBroadException
try:
bar.update(dl)
except:
pass
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ requests
googletrans
googlemaps
boto3
progressbar2

0 comments on commit d2f4011

Please sign in to comment.