Advertisement
anubischeats

dotnetprograms

Nov 11th, 2024 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. import requests
  2. import os
  3. import zipfile
  4.  
  5. def download_file(url, filename=None):
  6.     # Define the Downloads folder path
  7.     downloads_folder = os.path.join(os.path.expanduser("~"), "Downloads")
  8.    
  9.     # Use the provided filename or extract it from the URL
  10.     if filename is None:
  11.         filename = url.split("/")[-1]
  12.    
  13.     # Full path where the file will be saved
  14.     file_path = os.path.join(downloads_folder, filename)
  15.    
  16.     # Download the file
  17.     response = requests.get(url, stream=True)
  18.     if response.status_code == 200:
  19.         with open(file_path, "wb") as file:
  20.             for chunk in response.iter_content(1024):
  21.                 file.write(chunk)
  22.         #print(f"File downloaded successfully and saved as: {file_path}")
  23.     else:
  24.         print(f"Failed to download file. Status code: {response.status_code}")
  25.         return None  # Stop if the download failed
  26.    
  27.     # If the file is a zip, extract it
  28.     if zipfile.is_zipfile(file_path):
  29.         extract_folder = os.path.join(downloads_folder, filename.replace(".zip", ""))
  30.         os.makedirs(extract_folder, exist_ok=True)
  31.        
  32.         with zipfile.ZipFile(file_path, "r") as zip_ref:
  33.             zip_ref.extractall(extract_folder)
  34.         # print(f"File extracted successfully to: {extract_folder}")
  35.        
  36.         # Optionally, remove the downloaded zip file after extraction
  37.         os.remove(file_path)
  38.     else:
  39.         print("The downloaded file is not a zip file.")
  40.  
  41.  
  42. baseUrl = r'https://raw.githubusercontent.com/anubisthetyrant/dotnet/main/'
  43.  
  44. download_file(baseUrl + 'programs.zip')
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement