#!/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)