Skip to content

Instantly share code, notes, and snippets.

@daltonmatos
Created July 27, 2012 01:49
Show Gist options
  • Save daltonmatos/3185746 to your computer and use it in GitHub Desktop.
Save daltonmatos/3185746 to your computer and use it in GitHub Desktop.
Simple download function with progress bar
# Requires clint (https://github.com/kennethreitz/clint) from the develop branch, because of the expected_size argument.
def download(url, to_file, chunk_size=8192):
r = requests.get(url)
size = int(r.headers['Content-Length'])
expected_size = size / chunk_size
with open(to_file, 'w') as f:
for chunk in progress.bar(r.iter_content(chunk_size=chunk_size), expected_size=expected_size):
f.write(chunk)
@kennethreitz
Copy link

awesome :)

@daltonmatos
Copy link
Author

Thanks! It's my new wget! =P

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