From 29233cf0ae2657e20ea061ab850695cc95d376e0 Mon Sep 17 00:00:00 2001 From: Aniket-1020 Date: Tue, 13 Jun 2023 08:40:19 +0530 Subject: [PATCH] Adding Python Script for Automated File Download to specified path. --- .github/FileDownload Automationi/README.md | 61 ++++++++++++++++++++++ .github/FileDownload Automationi/script.py | 29 ++++++++++ 2 files changed, 90 insertions(+) create mode 100644 .github/FileDownload Automationi/README.md create mode 100644 .github/FileDownload Automationi/script.py diff --git a/.github/FileDownload Automationi/README.md b/.github/FileDownload Automationi/README.md new file mode 100644 index 0000000000..5a052da438 --- /dev/null +++ b/.github/FileDownload Automationi/README.md @@ -0,0 +1,61 @@ +# File Downloader + +This script allows you to easily download files from a given URL and save them to a local directory. It utilizes the `requests` library to handle the HTTP requests and provide a convenient way to download files. + +## Prerequisites + +Before running this script, ensure that you have the following installed: + +- Python 3.x +- The `requests` library. You can install it by running the following command: + + ``` + pip install requests + ``` + +## Usage + +1. Import the `requests` library: + + ```python + import requests + ``` + +2. Define the `download_file` function, which takes three parameters: `url`, `save_path`, and `file_name`. This function downloads the file from the provided URL and saves it to the specified location. + + ```python + def download_file(url, save_path, file_name): + response = requests.get(url) + file_path = save_path + "\\" + file_name + with open(file_path, 'wb') as file: + file.write(response.content) + print("File downloaded successfully!") + ``` + +3. Provide the necessary information: + + - Specify the URL of the file you want to download: + + ```python + file_url = "https://files.ceenaija.com/wp-content/uploads/music/2022/09/Keane_-_Somewhere_Only_We_Know_CeeNaija.com_.mp3" + ``` + + - Set the save path where you want to store the file. Replace `YOUR_SAVE_PATH` with the desired directory path: + + ```python + save_path = r"YOUR_SAVE_PATH" + ``` + + - Prompt the user to enter the desired file name: + + ```python + file_name = input("Enter the file name: ") + ``` + +4. Download the file by calling the `download_file` function with the provided parameters: + + ```python + download_file(file_url, save_path, file_name) + ``` + +The file will be downloaded and saved to the specified location. You can customize the script to fit your specific needs by modifying the URL, save path, and file name. diff --git a/.github/FileDownload Automationi/script.py b/.github/FileDownload Automationi/script.py new file mode 100644 index 0000000000..192fb4ccb0 --- /dev/null +++ b/.github/FileDownload Automationi/script.py @@ -0,0 +1,29 @@ +import requests + +def download_file(url, save_path, file_name): + """ + Download a file from a given URL and save it to a specified directory. + + Parameters: + - url (str): The URL of the file to be downloaded. + Get the URL of download button through it's inspect button. + - save_path (str): The directory path where the file will be saved. + - file_name (str): The name to be used for the downloaded file. + """ + response = requests.get(url) + file_path = save_path + "\\" + file_name + with open(file_path, 'wb') as file: + file.write(response.content) + print("File downloaded successfully!") + +# Example URL +file_url = "https://files.ceenaija.com/wp-content/uploads/music/2022/09/Keane_-_Somewhere_Only_We_Know_CeeNaija.com_.mp3" + +# Example save path +save_path = r"C:\Users\hp\Music" + +# Prompt user for file name +file_name = input("Enter the file name: ") + +# Download the file +download_file(file_url, save_path, file_name)