ipyvolume/utils.py
def download_to_file(url, filepath, resume=False, overwrite=False, chunk_size=1024*1024*10, loadbar_length=10):
    """ download a url

    prints a simple loading bar [=*loadbar_length] to show progress (in console and notebook)

    :type url: str
    :type filepath: str
    :param filepath: path to download to
    :param resume: if True resume download from existing file chunk
    :param overwrite: if True remove any existing filepath
    :param chunk_size: None or int in bytes
    :param loadbar_length: int length of load bar
    :return:
    """

    resume_header = None
    loaded_size = 0
    write_mode = 'wb'

    if os.path.exists(filepath):
        if overwrite:
            os.remove(filepath)
        elif resume:
            # if we want to resume, first try and see if the file is already complete
            loaded_size = os.path.getsize(filepath)
            clength = requests.head(url).headers.get('content-length')
            if clength is not None:
                if int(clength) == loaded_size:
                    return None
            # give the point to resume at
            resume_header = {'Range': 'bytes=%s-' % loaded_size}
            write_mode = 'ab'
        else:
            return None

    stream = False if chunk_size is None else True

    # start printing with no return character, so that we can have everything on one line
    print("Downloading {0:s}: ".format(url), end="")

    response = requests.get(url, stream=stream, headers=resume_header)
    # raise error if download was unsuccessful
    response.raise_for_status()

    # get the size of the file if available
    total_length = response.headers.get('content-length')
    if total_length is not None:
        total_length = float(total_length) + loaded_size
        print("{0:.2f}Mb/{1:} ".format(total_length / (1024 * 1024), loadbar_length), end="")
    print("[", end="")

    parent = os.path.dirname(filepath)
    if not os.path.exists(parent) and parent:
        os.makedirs(parent)

    with io.open(filepath, write_mode) as f:
        loaded = 0
        for chunk in response.iter_content(chunk_size=chunk_size):
            if chunk:  # filter out keep-alive new chunks
                # print our progress bar
                if total_length is not None and chunk_size is not None:
                    while loaded < loadbar_length*loaded_size/total_length:
                        print("=", end='')
                        loaded += 1
                    loaded_size += chunk_size
                f.write(chunk)
        if total_length is None:
            print("=" * loadbar_length, end='')
        else:
            while loaded < loadbar_length:
                print("=", end='')
                loaded += 1
    print("] Finished")
 download a url

    prints a simple loading bar [=*loadbar_length] to show progress (in console and notebook)

    :type url: str
    :type filepath: str
    :param filepath: path to download to
    :param resume: if True resume download from existing file chunk
    :param overwrite: if True remove any existing filepath
    :param chunk_size: None or int in bytes
    :param loadbar_length: int length of load bar
    :return:
    
download a url
prints a simple loading bar [=*loadbar_length] to show progress (in console and notebook)
download a url prints a simple loading bar [ = * loadbar_length ] to show progress ( in console and notebook )
def download_to_file(url, filepath, resume=False, overwrite=False, chunk_size=1024*1024*10, loadbar_length=10):
    resume_header = None
    loaded_size = 0
    write_mode = 'wb'
    if os.path.exists(filepath):
        if overwrite:
            os.remove(filepath)
        elif resume:
            loaded_size = os.path.getsize(filepath)
            clength = requests.head(url).headers.get('content-length')
            if clength is not None:
                if int(clength) == loaded_size:
                    return None
            resume_header = {'Range': 'bytes=%s-' % loaded_size}
            write_mode = 'ab'
        else:
            return None
    stream = False if chunk_size is None else True
    print("Downloading {0:s}: ".format(url), end="")
    response = requests.get(url, stream=stream, headers=resume_header)
    response.raise_for_status()
    total_length = response.headers.get('content-length')
    if total_length is not None:
        total_length = float(total_length) + loaded_size
        print("{0:.2f}Mb/{1:} ".format(total_length / (1024 * 1024), loadbar_length), end="")
    print("[", end="")
    parent = os.path.dirname(filepath)
    if not os.path.exists(parent) and parent:
        os.makedirs(parent)
    with io.open(filepath, write_mode) as f:
        loaded = 0
        for chunk in response.iter_content(chunk_size=chunk_size):
            if chunk:  
                if total_length is not None and chunk_size is not None:
                    while loaded < loadbar_length*loaded_size/total_length:
                        print("=", end='')
                        loaded += 1
                    loaded_size += chunk_size
                f.write(chunk)
        if total_length is None:
            print("=" * loadbar_length, end='')
        else:
            while loaded < loadbar_length:
                print("=", end='')
                loaded += 1
    print("] Finished")
def download_to_file ( url , filepath , resume = False , overwrite = False , chunk_size = 1024 * 1024 * 10 , loadbar_length = 10 ) : resume_header = None loaded_size = 0 write_mode = 'wb' if os . path . exists ( filepath ) : if overwrite : os . remove ( filepath ) elif resume : loaded_size = os . path . getsize ( filepath ) clength = requests . head ( url ) . headers . get ( 'content-length' ) if clength is not None : if int ( clength ) == loaded_size : return None resume_header = { 'Range' : 'bytes=%s-' % loaded_size } write_mode = 'ab' else : return None stream = False if chunk_size is None else True print ( "Downloading {0:s}: " . format ( url ) , end = "" ) response = requests . get ( url , stream = stream , headers = resume_header ) response . raise_for_status ( ) total_length = response . headers . get ( 'content-length' ) if total_length is not None : total_length = float ( total_length ) + loaded_size print ( "{0:.2f}Mb/{1:} " . format ( total_length / ( 1024 * 1024 ) , loadbar_length ) , end = "" ) print ( "[" , end = "" ) parent = os . path . dirname ( filepath ) if not os . path . exists ( parent ) and parent : os . makedirs ( parent ) with io . open ( filepath , write_mode ) as f : loaded = 0 for chunk in response . iter_content ( chunk_size = chunk_size ) : if chunk : if total_length is not None and chunk_size is not None : while loaded < loadbar_length * loaded_size / total_length : print ( "=" , end = '' ) loaded += 1 loaded_size += chunk_size f . write ( chunk ) if total_length is None : print ( "=" * loadbar_length , end = '' ) else : while loaded < loadbar_length : print ( "=" , end = '' ) loaded += 1 print ( "] Finished" )
download a url
prints a simple loading bar [=*loadbar_length] to show progress (in console and notebook)
download a url prints a simple loading bar [ = * loadbar_length ] to show progress ( in console and notebook )
""" download a url

    prints a simple loading bar [=*loadbar_length] to show progress (in console and notebook)

    :type url: str
    :type filepath: str
    :param filepath: path to download to
    :param resume: if True resume download from existing file chunk
    :param overwrite: if True remove any existing filepath
    :param chunk_size: None or int in bytes
    :param loadbar_length: int length of load bar
    :return:
    """ # if we want to resume, first try and see if the file is already complete # give the point to resume at # start printing with no return character, so that we can have everything on one line # raise error if download was unsuccessful # get the size of the file if available # filter out keep-alive new chunks # print our progress bar
None
url
filepath
path to download to
path to download to
resume
if True resume download from existing file chunk
if True resume download from existing file chunk
overwrite
if True remove any existing filepath
if True remove any existing filepath
chunk_size
None or int in bytes
None or int in bytes
loadbar_length
int length of load bar
int length of load bar