Created
March 26, 2014 20:36
-
-
Save quantum5/9792810 to your computer and use it in GitHub Desktop.
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
import os | |
def download(file, source, target): | |
size = int(source.info().getheaders('Content-Length')[0]) | |
print('Downloading {}, Size: {:,d}'.format(file, size)) | |
downloaded = 0 | |
block = 65536 | |
timer = [time.time, time.clock][os.name == 'nt'] | |
start = timer() | |
while True: | |
buf = source.read(block) | |
if not buf: | |
break | |
downloaded += len(buf) | |
target.write(buf) | |
print '{:15,d} [{:6.2f}%] {:9.2f} kB/s\r'.format( | |
downloaded, downloaded * 100. / size, | |
downloaded / 1024. / (timer() - start)), | |
print '{:15,d} [100.00%]'.format(downloaded) | |
source.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment