Forum Discussion

rockper's avatar
rockper
Frequent Visitor
2 years ago
Solved

Import multiple files from external source

Source: https://coast.noaa.gov/htdata/CMSP/AISDataHandler/2023/index.html Destination: my_lakehouse_root/files/ais/2023/ Lakehouse SQL Endpoint: xyz.datawarehouse.fabric.microsoft.com   I have su...
  • Anonymous's avatar
    Anonymous
    2 years ago

    I would donwload them via a python notebook instead

    Create an iterator that generates the needed urls. from 01_01 until 09_30

    download each url 

    https://coast.noaa.gov/htdata/CMSP/AISDataHandler/2023/AIS_2023_01_01.zip

     

    if you need inspiration on how to download files in python, then use the existing samples that you can install for free. The Machine detection one for example downloads its own data. 

     

    They all contain a code block that downloads a file and unzips it to the lakehouse. here is the example from the uplift sample

     

     

    if not IS_CUSTOM_DATA:
        # Download demo data files into lakehouse if not exist
        import os, requests

        download_file = "criteo-research-uplift-v2.1.csv.gz"
        download_path = f"/lakehouse/default/{DATA_FOLDER}/raw"

        if not os.path.exists("/lakehouse/default"😞
            raise FileNotFoundError("Default lakehouse not found, please add a lakehouse and restart the session.")
        os.makedirs(download_path, exist_ok=True)
        if not os.path.exists(f"{download_path}/{DATA_FILE}"😞
            r = requests.get(f"{remote_url}", timeout=30)
            with open(f"{download_path}/{download_file}", "wb") as f:
                f.write(r.content)
            with gzip.open(f"{download_path}/{download_file}", "rb") as fin:
                with open(f"{download_path}/{DATA_FILE}", "wb") as fout:
                    fout.write(fin.read())
        print("Downloaded demo data files into lakehouse.")
     
     
    Hope this will help you to get started with downloading data and loading your lakehouse.