Skip to content

Instantly share code, notes, and snippets.

Created February 6, 2018 23:50
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save skulltech/4510a5613c9aae89105fd1b6c424d0a0 to your computer and use it in GitHub Desktop.
Handy Python function for downloading file with progress bar
import sys
import requests
def download(url, filename):
with open(filename, 'wb') as f:
response = requests.get(url, stream=True)
total = response.headers.get('content-length')
if total is None:
downloaded = 0
total = int(total)
for data in response.iter_content(chunk_size=max(int(total / 1000), 1024 * 1024)):
downloaded += len(data)
done = int(50 * downloaded / total)
sys.stdout.write('\r[{}{}]'.format('█' * done, '.' * (50 - done)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment