def interactive_download(url, output_file, title='', chunk_size=(100 * 1024)):
 output_dir = os.path.dirname(output_file)
 output_file = open(output_file, 'w+b')
 input_file = urllib2.urlopen(url)
 try:
  file_size = int(input_file.headers['Content-Length'])
 except KeyError:
  raise ValueError('Could not find file size in HTTP headers')
 logging.info('Downloading %s, %s to %s', os.path.basename(url), display_data_size(file_size), output_dir)
 if title:
  width = (progressbar.ProgressBar.DEFAULT_WIDTH - len(title))
  progress_bar = progressbar.ProgressBar(maximum=file_size, width=width, title=title)
 else:
  progress_bar = progressbar.ProgressBar(maximum=file_size)
 progress_bar.update_screen()
 while True:
  data = input_file.read(chunk_size)
  if data:
   progress_bar.increment(len(data))
   output_file.write(data)
  else:
   progress_bar.update(file_size)
   print
   break
 output_file.close()

def interactive_download ( url , output_file , title = '' , chunk_size = ( 100 * 1024 ) ) : output_dir = os . path . dirname ( output_file ) output_file = open ( output_file , 'w+b' ) input_file = urllib2 . urlopen ( url ) try : file_size = int ( input_file . headers [ 'Content-Length' ] ) except KeyError : raise ValueError ( 'Could not find file size in HTTP headers' ) logging . info ( 'Downloading %s, %s to %s' , os . path . basename ( url ) , display_data_size ( file_size ) , output_dir ) if title : width = ( progressbar . ProgressBar . DEFAULT_WIDTH - len ( title ) ) progress_bar = progressbar . ProgressBar ( maximum = file_size , width = width , title = title ) else : progress_bar = progressbar . ProgressBar ( maximum = file_size ) progress_bar . update_screen ( ) while True : data = input_file . read ( chunk_size ) if data : progress_bar . increment ( len ( data ) ) output_file . write ( data ) else : progress_bar . update ( file_size ) print break output_file . close ( )
interactively downloads a given file url to a given output file :type url: string .