Skip to content

Instantly share code, notes, and snippets.

@mpslanker
Forked from gschizas/requestsprogress.py
Created March 17, 2013 13:24
Show Gist options
  • Save mpslanker/5181486 to your computer and use it in GitHub Desktop.
Save mpslanker/5181486 to your computer and use it in GitHub Desktop.
r = requests.get(file_url)
size = int(r.headers['Content-Length'].strip())
self.bytes = 0
widgets = [name, ": ", Bar(marker="|", left="[", right=" "),
Percentage(), " ", FileTransferSpeed(), "] ",
self,
" of {0}MB".format(str(round(size / 1024 / 1024, 2))[:4])]
pbar = ProgressBar(widgets=widgets, maxval=size).start()
file = []
for buf in r.iter_content(1024):
if buf:
file.append(buf)
self.bytes += len(buf)
pbar.update(self.bytes)
pbar.finish()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment