andrewbolster / bolster

Brain of Bolster, Be Ware
Other
3 stars 0 forks source link

Add Progress Bar to download_extract_zip #314

Open andrewbolster opened 2 years ago

andrewbolster commented 2 years ago
import requests, os
from tqdm import tqdm

eg_link = "https://caspersci.uk.to/matryoshka.zip"
response = requests.get(eg_link, stream=True)
with tqdm.wrapattr(open(os.devnull, "wb"), "write",
                   miniters=1, desc=eg_link.split('/')[-1],
                   total=int(response.headers.get('content-length', 0))) as fout:
    for chunk in response.iter_content(chunk_size=4096):
        fout.write(chunk)

From here https://github.com/tqdm/tqdm#hooks-and-callbacks Originally here https://stackoverflow.com/a/53877507/252556