Initial commit
This commit is contained in:
commit
b729fb9a3d
41
http_downloader.py
Normal file
41
http_downloader.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Usage:
|
||||||
|
./http_downloader.py <list_of_urls_filepath>
|
||||||
|
|
||||||
|
Description:
|
||||||
|
The program was intended to work as a simple downloader of multiple http urls using wget. The URLs are
|
||||||
|
given in the first parameter of the program. Then it reads every line of the file and interprets it as
|
||||||
|
one URL. Each line is passed to wget to download.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# some checks
|
||||||
|
if len(sys.argv) < 1: # something malicious, no start from shell! (when sys.argv is an empty list)
|
||||||
|
exit(1)
|
||||||
|
if len(sys.argv) == 1:
|
||||||
|
print(f"Usage: {sys.argv[0]} <list_of_urls_filepath>")
|
||||||
|
exit(1)
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
print(f"[WARNING] Only the first argument given will be used ({sys.argv[1]})")
|
||||||
|
|
||||||
|
# now sys.argv is shurely 2 elements in length; let the real process begin
|
||||||
|
try:
|
||||||
|
with open(sys.argv[1]) as f:
|
||||||
|
print(f"Opened {sys.argv[1]}, reading...")
|
||||||
|
urls = f.readlines()
|
||||||
|
for url in urls:
|
||||||
|
print(f"Getting {url}: ", end="") # print text, without newline at the end
|
||||||
|
returncode = subprocess.run(["wget", url], shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).returncode
|
||||||
|
if returncode != 0:
|
||||||
|
print(f"not a valid URL/not existent, skipping!")
|
||||||
|
print("100%.")
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"File \"{sys.argv[1]}\" could not be found, maybe not a file or path badly specified?")
|
||||||
|
exit(1)
|
3
test_list.txt
Normal file
3
test_list.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
https://example.org/
|
||||||
|
https://www.python.org/ftp/python/3.10.7/Python-3.10.7.tar.xz
|
||||||
|
https://pypi.org/project/pip
|
Loading…
x
Reference in New Issue
Block a user