From b729fb9a3d0fff7828a8fa71d83a515f1b8e86cb Mon Sep 17 00:00:00 2001 From: Blue Fox Date: Sat, 10 Sep 2022 08:07:14 +0200 Subject: [PATCH] Initial commit --- http_downloader.py | 41 +++++++++++++++++++++++++++++++++++++++++ test_list.txt | 3 +++ 2 files changed, 44 insertions(+) create mode 100644 http_downloader.py create mode 100644 test_list.txt diff --git a/http_downloader.py b/http_downloader.py new file mode 100644 index 0000000..b16ee7b --- /dev/null +++ b/http_downloader.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 + +""" +Usage: + ./http_downloader.py + +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]} ") + 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) diff --git a/test_list.txt b/test_list.txt new file mode 100644 index 0000000..2f19421 --- /dev/null +++ b/test_list.txt @@ -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