(url, file_name)
return True
Downloads the given url into the given file name
Downloads the given url into the given file name
Downloads the given url into the given file name
def do_download(url, file_name):
        """Downloads the given url into the given file name"""
        u = urllib.request.urlopen(url)
        f = open(file_name, 'wb')
        meta = u.info()
        if meta.get("Content-Length") and len(meta.get("Content-Length")) > 0:
            file_size = int(meta.get("Content-Length"))
            print("Downloading: %s Bytes: %s" % (file_name, file_size))

        block_sz = 8192
        count = 0
        while True:
            buff = u.read(block_sz)
            if not buff:
                break

            f.write(buff)
            if meta.get("Content-Length") and len(meta.get("Content-Length")) > 0 \
               and sys.stdout.isatty():
                count += len(buff)
                perc = (float(count) / float(file_size)) * 100.0
                str_perc = "%.1f%%" % perc
                sys.stdout.write('\r')
                sys.stdout.write(str_perc)
                sys.stdout.write(" " * (10 - len(str_perc)))

        print("")
        f.close()
        return True
def do_download ( url , file_name ) : u = urllib . request . urlopen ( url ) f = open ( file_name , 'wb' ) meta = u . info ( ) if meta . get ( "Content-Length" ) and len ( meta . get ( "Content-Length" ) ) > 0 : file_size = int ( meta . get ( "Content-Length" ) ) print ( "Downloading: %s Bytes: %s" % ( file_name , file_size ) ) block_sz = 8192 count = 0 while True : buff = u . read ( block_sz ) if not buff : break f . write ( buff ) if meta . get ( "Content-Length" ) and len ( meta . get ( "Content-Length" ) ) > 0 and sys . stdout . isatty ( ) : count += len ( buff ) perc = ( float ( count ) / float ( file_size ) ) * 100.0 str_perc = "%.1f%%" % perc sys . stdout . write ( '\r' ) sys . stdout . write ( str_perc ) sys . stdout . write ( " " * ( 10 - len ( str_perc ) ) ) print ( "" ) f . close ( ) return True