Return to Snippet

Revision: 64517
at August 16, 2013 21:25 by o0110o


Initial Code
def report(count, blockSize, totalSize):
  	percent = int(count*blockSize*100/totalSize)
  	sys.stdout.write("\r%d%%" % percent + ' complete')
  	sys.stdout.flush()

sys.stdout.write('\rFetching ' + name + '...\n')
urllib.urlretrieve(getFile, saveFile, reporthook=report)
sys.stdout.write("\rDownload complete, saved as %s" % (fileName) + '\n\n')
sys.stdout.flush()

Initial URL
http://stackoverflow.com/questions/51212/how-to-write-a-download-progress-indicator-in-python

Initial Description
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.

Initial Title
Display the download percentage of a file

Initial Tags
file, python, download

Initial Language
Python