code: def tqdm_hook(t):
      
      last_b = [0]
  
      def update_to(b=1, bsize=1, tsize=None):
          """
          b  : int, optional
              Number of blocks transferred so far [default: 1].
          bsize  : int, optional
              Size of each block (in tqdm units) [default: 1].
          tsize  : int, optional
              Total size (in tqdm units). If [default: None] remains unchanged.
          """
          if tsize is not None:
              t.total = tsize
          t.update((b - last_b[0]) * bsize)
          last_b[0] = b
  
      return update_to
docs: Wraps tqdm instance.
  
      Don't forget to close() or __exit__()
      the tqdm instance once you're done with it (easiest using `with` syntax).
      Example
      -------
      >>> with tqdm(...) as t:
      ...     reporthook = my_hook(t)
      ...     urllib.urlretrieve(..., reporthook=reporthook)