-
Notifications
You must be signed in to change notification settings - Fork 4
/
wget.py
executable file
·48 lines (38 loc) · 1.18 KB
/
wget.py
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
45
46
47
48
#!/usr/bin/env python
########################################################################
# wget.py: Simple Python-based File Downloader
#
# Description:
# This Python script downloads a file from a given URL and saves it
# locally. It mimics basic functionality of the wget command.
#
# Author: id774 (More info: http://id774.net)
# Source Code: https://github.com/id774/scripts
# License: LGPLv3 (Details: https://www.gnu.org/licenses/lgpl-3.0.html)
# Contact: [email protected]
#
# Version History:
# v1.1 2023-12-08
# Removed f-strings for compatibility with Python versions below 3.6.
# v1.0 2023-12-06
# Initial release.
#
# Usage:
# python wget.py <URL>
# Example: python wget.py http://example.com/file.txt
#
########################################################################
import sys
import requests
def usage():
print("Usage: {} <URL>".format(sys.argv[0]))
sys.exit(1)
def download_file(url):
response = requests.get(url)
filename = url.split('/')[-1]
with open(filename, 'wb') as file:
file.write(response.content)
if __name__ == "__main__":
if len(sys.argv) != 2:
usage()
download_file(sys.argv[1])