Skip to content

Instantly share code, notes, and snippets.

@nikhilkumarsingh
Last active June 24, 2024 12:15
Show Gist options
  • Save nikhilkumarsingh/d29c1fdec0f4e266e53137d96b52e289 to your computer and use it in GitHub Desktop.
Save nikhilkumarsingh/d29c1fdec0f4e266e53137d96b52e289 to your computer and use it in GitHub Desktop.
A file downloader with progress bar for terminal
from tqdm import tqdm
import requests
chunk_size = 1024
url = "http://www.nervenet.org/pdf/python3handson.pdf"
r = requests.get(url, stream = True)
total_size = int(r.headers['content-length'])
filename = url.split('/')[-1]
with open(filename, 'wb') as f:
for data in tqdm(iterable = r.iter_content(chunk_size = chunk_size), total = total_size/chunk_size, unit = 'KB'):
f.write(data)
print("Download complete!")
@RohanFarooqui
Copy link

<3

@gh-doot
Copy link

gh-doot commented Jul 19, 2020

Traceback (most recent call last):
File "c:/Users//Desktop/core/ProgressBar/installer.py", line 10, in
total_size = int(r.headers['content-length'])
File "C:\Users*
*********\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\structures.py", line 54, in getitem
return self._store[key.lower()][1]
KeyError: 'content-length'

@eli2and40
Copy link

Hey, thanks, teacher!
I was inspired by this project and wrote something you may, or may not, find useful!
It helps to keep file systems collision free

https://gist.github.com/ksabalo/365ca429eea3c6772e4ac2346dda00cd

@gh-doot
Copy link

gh-doot commented Aug 10, 2020

Thanks so much bro! I credited you also here's my improved version!
*btw its named pystore*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment