Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python urllib.request.urlretrieve with a progressbar

import progressbar

class MyProgressBar():
    def __init__(self):
        self.pbar = None

    def __call__(self, block_num, block_size, total_size):
        if not self.pbar:
            self.pbar=progressbar.ProgressBar(maxval=total_size)
            self.pbar.start()

        downloaded = block_num * block_size
        if downloaded < total_size:
            self.pbar.update(downloaded)
        else:
            self.pbar.finish()

# call :
urllib.request.urlretrieve('img_url', 'img_filename', MyProgressBar())
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #progressbar
ADD COMMENT
Topic
Name
3+4 =