Skip to content

Instantly share code, notes, and snippets.

@sorz
Created August 24, 2016 16:24
Show Gist options
  • Save sorz/32d21bcec47e017d7b91562c0a3e8aa8 to your computer and use it in GitHub Desktop.
Save sorz/32d21bcec47e017d7b91562c0a3e8aa8 to your computer and use it in GitHub Desktop.
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