-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathttp.py
108 lines (84 loc) · 4.07 KB
/
ttp.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
105
106
107
108
#!/usr/bin/env python3
"""Entrypoint into the script where the arguments are passed to src.main"""
import argparse
import sys
from datetime import datetime
from src.config import Config
from src.main import main
from src.schedule_retriever import ScheduleRetriever
__version__ = "1.3.0"
def add_arguments(parser: argparse.ArgumentParser):
parser.add_argument('-v', '--version',
action='version',
version=f'%(prog)s {__version__}',
help='show the current version and exit')
parser.add_argument('-t', '--test-notifications',
action='store_true',
help='test the notification and exit')
parser.add_argument('-d', '--current-appointment-date',
type=str,
help='Current appointment date in the format "Month Day, Year" (e.g. "December 31, 2023")')
parser.add_argument('-l', '--location-ids',
type=str,
help='Comma-separated list of location IDs (e.g. 1020,1030)')
parser.add_argument('-n', '--notification-level',
type=int,
help='Notification level (e.g. 1)')
parser.add_argument('-u', '--notification-urls',
type=str,
help='Comma-separated list of notification URLs in the Apprise format (e.g. discord://id/token,discord://id/token)')
parser.add_argument('-r', '--retrieval-interval',
type=str,
help='Retrieval interval in specified unit (e.g. 5m)')
parser.add_argument('-s', '--start-appointment-time',
type=str,
help='The earliest appointment time you would like to be notified for in HH:MM format (e.g. 08:00)')
parser.add_argument('-e', '--end-appointment-time',
type=str,
help='The latest appointment time you would like to be notified for in in HH:MM format (e.g. 17:00)')
def config_from_arguments(args):
if args.current_appointment_date:
config.current_appointment_date = datetime.strptime(args.current_appointment_date, '%B %d, %Y')
if args.location_ids:
location_ids = [int(x) for x in args.location_ids.split(',')]
for location_id in location_ids:
if location_id not in config.location_ids:
config.location_ids.append(location_id)
if args.notification_level:
config.notification_level = args.notification_level
if args.notification_urls:
notification_urls = args.notification_urls.split(',')
for notification_url in notification_urls:
if notification_url not in config.notification_urls:
config.notification_urls.append(notification_url)
if args.retrieval_interval:
try:
config.retrieval_interval = config.convert_to_seconds(args.retrieval_interval)
except ValueError as err:
raise TypeError(err)
if args.start_appointment_time:
try:
config.start_appointment_time = config.convert_to_datetime(args.start_appointment_time)
except ValueError as err:
raise TypeError(err)
if args.end_appointment_time:
try:
config.end_appointment_time = config.convert_to_datetime(args.end_appointment_time)
except ValueError as err:
raise TypeError(err)
if args.test_notifications:
schedule_retriever = ScheduleRetriever(config)
print("Sending test notifications...")
schedule_retriever.notification_handler.send_notification("This is a test message.")
sys.exit()
if __name__ == "__main__":
config = Config()
parser = argparse.ArgumentParser(description="Parse command line arguments")
add_arguments(parser)
args = parser.parse_args()
config_from_arguments(args)
try:
main(config)
except KeyboardInterrupt:
print("\nCtrl+C pressed. Stopping all checkins")
sys.exit()