Created
October 7, 2022 17:52
-
-
Save maxpoletaev/521c4ce2f5431a4afabf19383fc84fe2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
""" | |
Usage: | |
urlretrieve(source_url, filename, reporthook=ProgressBar()) | |
""" | |
class ProgressBar: | |
def __init__(self): | |
self.tqdm = None | |
def __call__(self, block_num, block_size, total_size): | |
if self.tqdm is None: | |
self.tqdm = tqdm( | |
total=total_size, | |
unit_divisor=1024, | |
unit_scale=True, | |
unit="B", | |
leave=False, | |
) | |
progress = block_num * block_size | |
if progress >= total_size: | |
self.tqdm.close() | |
return | |
self.tqdm.update(progress - self.tqdm.n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment