Created
August 24, 2016 16:24
-
-
Save sorz/32d21bcec47e017d7b91562c0a3e8aa8 to your computer and use it in GitHub Desktop.
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
import requests | |
URL = 'http://speedtest-sfo1.digitalocean.com/10mb.test' | |
headers = {'User-Agent': '-.-'} | |
resp = requests.get(URL, headers=headers, stream=True) | |
totalsize = int(resp.headers.get('content-length', '0')) | |
with open('10mb.test', 'wb') as f: | |
downsize = 0 | |
for chunk in resp.iter_content(1024 * 100): | |
f.write(chunk) | |
downsize += len(chunk) | |
if totalsize: | |
s = "%3.2f%% ====> %.2f MiB / %.2f MiB" % \ | |
(downsize / totalsize * 100, | |
downsize / 1024 / 1024, | |
totalsize / 1024 / 1024) | |
print(s, end='\r') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment