src/01_download/01_download_data.py
def main(file_path, urls):
    """
    Loads files from the array of urls and saves the
    downloaded files to the provided file path.
    """
    # format urls input
    with open(urls, 'r') as file:
        urls = file.read().replace('\n', '')

    urls = urls.strip('[]')
    urls = re.findall(r'\([^\)\(]*\)', urls)

    for file in urls:

        file_name, url = tuple(file.strip('()').split(', '))

        # check if file is already downloaded
        if os.path.exists(os.path.join(file_path, file_name)):
            print("%s already exists.\n" % file_name)
            continue
        else:
            print("Starting download for %s...\n" % file_name)

            # Create the data subdirectory if it doesn't exist
            os.makedirs(file_path, exist_ok=True)

            # create response object
            r = requests.get(url, stream=True)
            widgets = ["Progress: ",
                       progressbar.DataSize(), "| ",
                       progressbar.Timer()]
            bar = progressbar.ProgressBar(widgets=widgets,
                                          max_value=progressbar.UnknownLength)
            value = 0
            # download started
            with open(os.path.join(file_path, file_name), 'wb') as f:
                for chunk in r.iter_content(chunk_size=64*1024):
                    if chunk:
                        f.write(chunk)
                        value += len(chunk)
                        bar.update(value)

            print("\n%s downloaded!\n" % file_name)

    print("All files downloaded!")

    Loads files from the array of urls and saves the
    downloaded files to the provided file path.
    
Loads files from the array of urls and saves the
downloaded files to the provided file path.
Loads files from the array of urls and saves the downloaded files to the provided file path .
def main(file_path, urls):
    with open(urls, 'r') as file:
        urls = file.read().replace('\n', '')
    urls = urls.strip('[]')
    urls = re.findall(r'\([^\)\(]*\)', urls)
    for file in urls:
        file_name, url = tuple(file.strip('()').split(', '))
        if os.path.exists(os.path.join(file_path, file_name)):
            print("%s already exists.\n" % file_name)
            continue
        else:
            print("Starting download for %s...\n" % file_name)
            os.makedirs(file_path, exist_ok=True)
            r = requests.get(url, stream=True)
            widgets = ["Progress: ",
                       progressbar.DataSize(), "| ",
                       progressbar.Timer()]
            bar = progressbar.ProgressBar(widgets=widgets,
                                          max_value=progressbar.UnknownLength)
            value = 0
            with open(os.path.join(file_path, file_name), 'wb') as f:
                for chunk in r.iter_content(chunk_size=64*1024):
                    if chunk:
                        f.write(chunk)
                        value += len(chunk)
                        bar.update(value)
            print("\n%s downloaded!\n" % file_name)
    print("All files downloaded!")
def main ( file_path , urls ) : with open ( urls , 'r' ) as file : urls = file . read ( ) . replace ( '\n' , '' ) urls = urls . strip ( '[]' ) urls = re . findall ( r'\([^\)\(]*\)' , urls ) for file in urls : file_name , url = tuple ( file . strip ( '()' ) . split ( ', ' ) ) if os . path . exists ( os . path . join ( file_path , file_name ) ) : print ( "%s already exists.\n" % file_name ) continue else : print ( "Starting download for %s...\n" % file_name ) os . makedirs ( file_path , exist_ok = True ) r = requests . get ( url , stream = True ) widgets = [ "Progress: " , progressbar . DataSize ( ) , "| " , progressbar . Timer ( ) ] bar = progressbar . ProgressBar ( widgets = widgets , max_value = progressbar . UnknownLength ) value = 0 with open ( os . path . join ( file_path , file_name ) , 'wb' ) as f : for chunk in r . iter_content ( chunk_size = 64 * 1024 ) : if chunk : f . write ( chunk ) value += len ( chunk ) bar . update ( value ) print ( "\n%s downloaded!\n" % file_name ) print ( "All files downloaded!" )
Loads files from the array of urls and saves the
downloaded files to the provided file path.
Loads files from the array of urls and saves the downloaded files to the provided file path .
"""
    Loads files from the array of urls and saves the
    downloaded files to the provided file path.
    """ # format urls input # check if file is already downloaded # Create the data subdirectory if it doesn't exist # create response object # download started
file_path
urls