File size: 1,391 Bytes
c94bdef
 
 
 
ecaaef9
 
c94bdef
 
a97612b
 
c94bdef
 
 
 
 
 
 
 
a97612b
c94bdef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3eff7cc
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
import zipfile
import os

URL = os.getenv('URL')

def download_and_extract_zip(url, destination_folder):
    """Downloads a zip file from a URL and extracts its contents to the specified destination folder."""
    zip_file_path = "temp.zip"
    
    try:
        # Send an HTTP GET request to the OneDrive link to download the file
        response = requests.get(url)

        # Check if the request was successful (status code 200)
        response.raise_for_status()

        # Save the zip file to a temporary location
        
        with open(zip_file_path, "wb") as f:
            f.write(response.content)

        # Create the destination folder if it doesn't exist
        os.makedirs(destination_folder, exist_ok=True)

        # Extract the contents of the zip file
        with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
            zip_ref.extractall(destination_folder)

        print(f"Zip file downloaded and extracted to: {destination_folder}")

    except requests.exceptions.RequestException as e:
        print(f"Error downloading file: {e}")

    finally:
        # Remove the temporary zip file
        if os.path.exists(zip_file_path):
            os.remove(zip_file_path)


# Call the function to download and extract the data
if __name__ == "__main__":
    destination_folder = os.getcwd()
    download_and_extract_zip(URL, destination_folder)