Created
July 27, 2012 01:49
-
-
Save daltonmatos/3185746 to your computer and use it in GitHub Desktop.
Simple download function with progress bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
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
awesome :)