from urllib2 import urlopen # Open up remote and local file outfile = file(filename, 'wb') urlfile = urlopen(self.url) filesize = int(urlfile.info().get('Content-Length', None)) # Report beginning of download print 'Beginning download of: %s' % url print '\tSize:', if filesize is None: print 'Unknown' else: print "%d KB" % (self.filesize / 1024) print '\tTo Local File:',self.filename start_time = time.time() # Download our file total_read = 0 while 1: bytes = urlfile.read(Download.CHUNK_SIZE) bytes_read = len(bytes) # If its zero we have hit the end of the file if 0 == bytes_read: break # Write our data to the file outfile.write(bytes) # Update status information total_read += bytes_read print_status(filesize, total_read) # Report download stats total_time = time.time() - start_time total_read /= 1024 print '\nDownloaded: %d KB in %.2f seconds for %.2f KBs' % ( total_read, total_time, total_read/total_time)