Skip to content

Instantly share code, notes, and snippets.

@TakesxiSximada
Created July 5, 2016 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TakesxiSximada/5f8d41cd81fe40e970249fc6da3aea60 to your computer and use it in GitHub Desktop.
Save TakesxiSximada/5f8d41cd81fe40e970249fc6da3aea60 to your computer and use it in GitHub Desktop.
プログレスバー
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