-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
all.py
104 lines (88 loc) · 3.61 KB
/
all.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'''
all.py
Hussein Esmail
Created: 2022 01 03
Updated: 2023 11 11
Description: This program is meant to run all the other RSS parser programs in
this folder. The reason this is not a .bashrc alias is because arguments
that are parsed to this program will be carried over to all the programs
this one runs, such as --verbose, --quiet, --version, etc.
'''
from os import path, system # Less memory than importing the entire os library
from sys import exit # Less memory than importing the entire sys library
from glob import glob # Lists all files in directory with wildcard
import argparse # Parses given arguments
# ========= VARIABLES ===========
path_src_folder = "src/" # Where the RSS program files are stored
paths_exclude = [
"rss_html.py",
"rss_reddit_imgdl.py",
"rss_yfile.py",
"rss_tiktok.py",
"rss_scaruffi.py",
"rss_workinculture.py"
] # Programs to exclude even if they meet all requirements
# rss_yfile.py: I personally don't use this file anymore
# rss_scaruffi.py: Request by someone else
# rss_workinculture.py: Work in progress
# ========= COLOR CODES =========
color_end = '\033[0m'
color_darkgrey = '\033[90m'
color_red = '\033[91m'
color_green = '\033[92m'
color_yellow = '\033[93m'
color_blue = '\033[94m'
color_pink = '\033[95m'
color_cyan = '\033[96m'
color_white = '\033[97m'
color_grey = '\033[98m'
# ========= COLORED STRINGS =========
str_prefix_q = f"[{color_pink}Q{color_end}]"
str_prefix_y_n = f"[{color_pink}y/n{color_end}]"
str_prefix_ques = f"{str_prefix_q}\t "
str_prefix_err = f"[{color_red}ERROR{color_end}]\t "
str_prefix_done = f"[{color_green}DONE{color_end}]\t "
str_prefix_info = f"[{color_cyan}INFO{color_end}]\t "
error_neither_y_n = "You must either type 'y' or 'n' (or 'q' to exit)"
def yes_or_no(str_ask):
while True:
y_n = input(f"{str_prefix_q} {str_prefix_y_n} {str_ask}").lower()
if y_n[0] == "y":
return True
elif y_n[0] == "n":
return False
if y_n[0] == "q":
exit()
else:
print(f"{str_prefix_err} {error_neither_y_n}")
def main():
parser = argparse.ArgumentParser()
# Commands to create
parser.add_argument("-v", "--verbose", action="store_true",help="Verbose mode", dest="verbose")
parser.add_argument("-q", "--quiet", action="store_true", help="Quiet mode (overrides --verbose)", dest="quiet")
args = parser.parse_args()
if args.verbose and args.quiet:
print(str_prefix_err + "Cannot have --verbose and --quiet. Using --quiet")
args.verbose = False
# Path of where this Python file is
path_this_file = path.dirname(path.realpath(__file__))
# Program must contain "rss" in filename and be in same folder
programs_run = glob(f"{path_this_file}/{path_src_folder}/*rss*.py".replace("//", "/"))
# Removing excluded programs to run
programs_run = sorted([program for program in programs_run if program.split("/")[-1] not in paths_exclude])
args_send = " " # Arguments to send
if args.quiet:
if len(args_send.strip()) == 0:
args_send += "-"
args_send += "q"
elif args.verbose:
if len(args_send.strip()) == 0:
args_send += "-"
args_send += "v"
for program_run in programs_run:
if not args.quiet:
print(str_prefix_info + "Running " + program_run.split("/")[-1] + args_send)
system("python3 " + program_run + args_send)
exit()
if __name__ == "__main__":
main()