0

I want to download a large file and then create a graph of the download speed every second

To see if there are any disconnections in the middle or falls of speed

I saw that Python progress bar and downloads

But it only gives me a percentage by download.
Is there a way to record the speed every second?

import sys
import requests

link = "http://indy/abcde1245"
file_name = "download.data"
with open(file_name, "wb") as f:
print("Downloading %s" % file_name)
response = requests.get(link, stream=True)
total_length = response.headers.get('content-length')

if total_length is None: # no content length header
    f.write(response.content)
else:
    dl = 0
    total_length = int(total_length)
    for data in response.iter_content(chunk_size=4096):
        dl += len(data)
        f.write(data)
        done = int(50 * dl / total_length)
        sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50-done)) )    
        sys.stdout.flush()
yosi
  • 45
  • 5

0 Answers0