Skip to content

Commit 29233cf

Browse files
committed
Adding Python Script for Automated File Download to specified path.
1 parent f8a43c6 commit 29233cf

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# File Downloader
2+
3+
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.
4+
5+
## Prerequisites
6+
7+
Before running this script, ensure that you have the following installed:
8+
9+
- Python 3.x
10+
- The `requests` library. You can install it by running the following command:
11+
12+
```
13+
pip install requests
14+
```
15+
16+
## Usage
17+
18+
1. Import the `requests` library:
19+
20+
```python
21+
import requests
22+
```
23+
24+
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.
25+
26+
```python
27+
def download_file(url, save_path, file_name):
28+
response = requests.get(url)
29+
file_path = save_path + "\\" + file_name
30+
with open(file_path, 'wb') as file:
31+
file.write(response.content)
32+
print("File downloaded successfully!")
33+
```
34+
35+
3. Provide the necessary information:
36+
37+
- Specify the URL of the file you want to download:
38+
39+
```python
40+
file_url = "https://files.ceenaija.com/wp-content/uploads/music/2022/09/Keane_-_Somewhere_Only_We_Know_CeeNaija.com_.mp3"
41+
```
42+
43+
- Set the save path where you want to store the file. Replace `YOUR_SAVE_PATH` with the desired directory path:
44+
45+
```python
46+
save_path = r"YOUR_SAVE_PATH"
47+
```
48+
49+
- Prompt the user to enter the desired file name:
50+
51+
```python
52+
file_name = input("Enter the file name: ")
53+
```
54+
55+
4. Download the file by calling the `download_file` function with the provided parameters:
56+
57+
```python
58+
download_file(file_url, save_path, file_name)
59+
```
60+
61+
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.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import requests
2+
3+
def download_file(url, save_path, file_name):
4+
"""
5+
Download a file from a given URL and save it to a specified directory.
6+
7+
Parameters:
8+
- url (str): The URL of the file to be downloaded.
9+
Get the URL of download button through it's inspect button.
10+
- save_path (str): The directory path where the file will be saved.
11+
- file_name (str): The name to be used for the downloaded file.
12+
"""
13+
response = requests.get(url)
14+
file_path = save_path + "\\" + file_name
15+
with open(file_path, 'wb') as file:
16+
file.write(response.content)
17+
print("File downloaded successfully!")
18+
19+
# Example URL
20+
file_url = "https://files.ceenaija.com/wp-content/uploads/music/2022/09/Keane_-_Somewhere_Only_We_Know_CeeNaija.com_.mp3"
21+
22+
# Example save path
23+
save_path = r"C:\Users\hp\Music"
24+
25+
# Prompt user for file name
26+
file_name = input("Enter the file name: ")
27+
28+
# Download the file
29+
download_file(file_url, save_path, file_name)

0 commit comments

Comments
 (0)