Posted By

o0110o on 08/16/13


file python download progress transfer percentage

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Display the download percentage of a file

 / Published in: Python


Place this snippent in your script, and call it like this: urllib.urlretrieve(getFile, saveFile, reporthook=report)

Notice it is the 3rd argument that calls the function on each file that needs to be downloaded.

  1. def report(count, blockSize, totalSize):
  2. percent = int(count*blockSize*100/totalSize)
  3. sys.stdout.write("\r%d%%" % percent + ' complete')
  4. sys.stdout.flush()
  6. sys.stdout.write('\rFetching ' + name + '...\n')
  7. urllib.urlretrieve(getFile, saveFile, reporthook=report)
  8. sys.stdout.write("\rDownload complete, saved as %s" % (fileName) + '\n\n')
  9. sys.stdout.flush()

Report this snippet  

You need to login to post a comment.