Skip to content

Instantly share code, notes, and snippets.

@redanium
Forked from gschizas/requestsprogress.py
Created December 21, 2017 17:05
Show Gist options
  • Save redanium/ed10e9cd0b4d0f4445a5dc8648d724c1 to your computer and use it in GitHub Desktop.
Save redanium/ed10e9cd0b4d0f4445a5dc8648d724c1 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