-
-
Save redanium/ed10e9cd0b4d0f4445a5dc8648d724c1 to your computer and use it in GitHub Desktop.
Requests with progressbar in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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