Created
December 5, 2018 03:26
-
-
Save clasqui/a0ded7070b0daf3031d5110b3b45bd5d to your computer and use it in GitHub Desktop.
Script temps de descàrrega per B7 de PE (FIB-UPC)
This file contains hidden or 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
#!/usr/local/bin/python3 | |
import sys | |
import requests | |
import time | |
if len(sys.argv) < 2: | |
print('Usage: downloadtime.py [URL]') | |
sys.exit(0) | |
url = sys.argv[1] | |
local_filename = url.split('/')[-1] | |
with open(local_filename, 'wb') as f: | |
start = time.time() | |
r = requests.get(url, stream=True) | |
print ("Download starting") | |
total_length = r.headers.get('content-length') | |
dl = 0 | |
if total_length is None: | |
f.write(r.content) | |
else: | |
for chunk in r.iter_content(1024*10000): | |
dl += len(chunk) | |
f.write(chunk) | |
done = int((float(dl) / float(total_length)) * 100) | |
sys.stdout.write("\rDownload progress: %s%s" % (done, '%')) | |
print ('') | |
print("Download complete...") | |
print ("Time elapsed: ", time.time() - start) | |
# https://www.thinkbroadband.com/download |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment