title: create download graph with python
body: <p>I want to download a large file and then create a graph of the download speed every second</p>
  <p>To see if there are any disconnections in the middle or falls of speed</p>
  <p>I saw that <a href="https://stackoverflow.com/questions/15644964/python-progress-bar-and-downloads/15645088#15645088">Python progress bar and downloads</a></p>
  <p>But it only gives me a percentage by download.<br />
  Is there a way to record the speed every second?</p>
  <pre><code>import sys
  import requests
  
  link = &quot;http://indy/abcde1245&quot;
  file_name = &quot;download.data&quot;
  with open(file_name, &quot;wb&quot;) as f:
  print(&quot;Downloading %s&quot; % 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(&quot;\r[%s%s]&quot; % ('=' * done, ' ' * (50-done)) )    
          sys.stdout.flush()
  </code></pre>