This repository has been archived by the owner on Dec 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
finder.py
89 lines (69 loc) · 2.56 KB
/
finder.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
import argparse
import logging
from importlib import import_module
from types import ModuleType
from src.helpers import logger
# Create a logger
log = logging.getLogger("vss365today-finder")
log.addHandler(logger.file_handler())
def get_task_main(module_name: str) -> ModuleType:
"""Import a task module."""
return import_module(f"src.core.{module_name}")
def handle_prompt_command(args: argparse.Namespace) -> bool:
if args.manual:
logging.info("Running manual Prompt...")
return get_task_main("manual").main() # type: ignore
logging.info("Running fetch Prompt...")
return get_task_main("fetch").main() # type: ignore
def handle_schedule_command(args: argparse.Namespace) -> bool:
if args.prompt:
logging.info("Starting scheduled Prompt fetch...")
return get_task_main("fetch").schedule() # type: ignore
if args.backup:
logging.info("Starting scheduled Prompt images backup...")
return get_task_main("backup").schedule() # type: ignore
return False
# Handle app arguments
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
# Archive file generation
parser_archive = subparsers.add_parser("archive", help="archive help")
parser_archive.set_defaults(func=get_task_main("archive").main) # type: ignore
# Static file backup
parser_backup = subparsers.add_parser("backup", help="backup help")
parser_backup.set_defaults(func=get_task_main("backup").main) # type: ignore
# Notif email sending
parser_email = subparsers.add_parser("email", help="email help")
parser_email.set_defaults(func=get_task_main("email").main) # type: ignore
# Prompt recording actions
parser_prompt = subparsers.add_parser("prompt", help="prompt help")
group_prompt = parser_prompt.add_mutually_exclusive_group()
group_prompt.add_argument(
"-m",
"--manual",
help="manually record a specific Prompt.",
action="store_true",
)
parser_prompt.set_defaults(func=handle_prompt_command)
# Scheduled tasks
parser_schedule = subparsers.add_parser("schedule", help="schedule help")
group_schedule = parser_schedule.add_mutually_exclusive_group()
group_schedule.add_argument(
"-p",
"--prompt",
help="schedule recording the latest Prompt according to ENV values.",
action="store_true",
)
group_schedule.add_argument(
"-b",
"--backup",
help="schedule a backup of Prompt images.",
action="store_true",
)
parser_schedule.set_defaults(func=handle_schedule_command)
# Run the proper commands
try:
args = parser.parse_args()
args.func(args)
except AttributeError:
parser.print_help()