I am trying to tune a progress bar using the Tqdm module in python 3.6, but it seems I'm halfway there.
My code is as follows:
from tqdm import tqdm
import requests
import time
url = 'http://alpha.chem.umb.edu/chemistry/ch115/Mridula/CHEM%20116/documents/chapter_20au.pdf'
r = requests.get(url, stream=True)
local_filename = url.split('/')[-1]
total_size = int(r.headers.get('content-length', 0))
print(total_size)
with open(local_filename, 'wb') as f:
for data in tqdm(r.iter_content(chunk_size = 512), total=total_size, unit='B', unit_scale=True):
f.write(data)
The problem is that when I insert chunk_size = 512in r.iter_content, the progress bar does not load at all when showing the loaded data, but when I completely delete chunk_size = 512and leave the parentheses empty, the bar loads in the same way as it should, but the download speed is terrible.
What am I doing wrong here?
source
share