Skip to content

Instantly share code, notes, and snippets.

@gschizas
Created September 16, 2012 11:04
Show Gist options
  • Save gschizas/3731992 to your computer and use it in GitHub Desktop.
Save gschizas/3731992 to your computer and use it in GitHub Desktop.
Requests with progressbar in python
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