You are on page 1of 1

import sys, os, urllib2 #get parameter fURL = sys.argv[1] #open the url u = urllib2.

urlopen(fURL) #get the size meta = u.info() fname = os.path.basename(fURL) fsize = float(meta.getheaders("Content-Length")[0]) #convert size to readable format sizeSuffix = ['b','Kb','Mb','Gb','Tb'] idx = 0; #while fsize>1024: # fsize = fsize / 1024.0 # idx += 1 print "downloading "+fname+" ("+str(round(fsize,2))+sizeSuffix[idx]+")" #download the file lf = open(fname,'w') lf.write(u.read()) lf.close()

You might also like