Created
July 5, 2016 13:23
-
-
Save TakesxiSximada/5f8d41cd81fe40e970249fc6da3aea60 to your computer and use it in GitHub Desktop.
プログレスバー
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
import io | |
import pycurl | |
import progressbar | |
fp = io.BytesIO() | |
curl = pycurl.Curl() | |
curl.setopt(pycurl.URL, 'おおきなファイルのURL') # noqa | |
curl.setopt(pycurl.NOPROGRESS, 0) | |
curl.setopt(pycurl.WRITEDATA, fp) | |
progress = progressbar.ProgressBar() | |
def update(total_to_download, total_downloaded, total_to_upload, total_uploaded): | |
if total_to_download: | |
percent = int(total_downloaded / total_to_download * 100) | |
progress.update(percent) | |
curl.setopt(pycurl.PROGRESSFUNCTION, update) | |
try: | |
progress.start() | |
curl.perform() | |
finally: | |
progress.finish() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment