Skip to content

Instantly share code, notes, and snippets.

@maxpoletaev
Created October 7, 2022 17:52
Show Gist options
  • Save maxpoletaev/521c4ce2f5431a4afabf19383fc84fe2 to your computer and use it in GitHub Desktop.
Save maxpoletaev/521c4ce2f5431a4afabf19383fc84fe2 to your computer and use it in GitHub Desktop.
"""
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