34
|
1 import datetime
|
|
2 import json
|
|
3 from pprint import pprint
|
|
4
|
|
5 import tzlocal
|
|
6
|
|
7 from calendar_connection import getCalendarService
|
|
8
|
46
|
9 holidays = {
|
|
10 "2024-09-02": "Labor Day (school closed)",
|
|
11 "2024-10-07": "Staff Development (school closed)",
|
|
12 "2024-11-01": "Confs. & Staff Dev. (school closed)",
|
|
13 "2024-11-11": "Veteran's Day (school closed)",
|
|
14 "2024-11-25": "Thanksgiving Break (school closed)",
|
|
15 "2024-11-26": "Thanksgiving Break (school closed)",
|
|
16 "2024-11-27": "Thanksgiving Break (school closed)",
|
|
17 "2024-11-28": "Thanksgiving Break (school closed)",
|
|
18 "2024-11-29": "Thanksgiving Break (school closed)",
|
|
19 "2024-12-23": "Winter Recess (school closed)",
|
|
20 "2024-12-24": "Winter Recess (school closed)",
|
|
21 "2024-12-25": "Winter Recess (school closed)",
|
|
22 "2024-12-26": "Winter Recess (school closed)",
|
|
23 "2024-12-27": "Winter Recess (school closed)",
|
|
24 "2024-12-30": "Winter Recess (school closed)",
|
|
25 "2024-12-31": "Winter Recess (school closed)",
|
|
26 "2025-01-01": "Winter Recess (school closed)",
|
|
27 "2025-01-02": "Winter Recess (school closed)",
|
|
28 "2025-01-03": "Winter Recess (school closed)",
|
|
29 "2025-01-20": "MLK's Birthday (school closed)",
|
|
30 "2025-01-27": "Staff Development Day (school closed)",
|
|
31 "2025-02-14": "Lincoln's Birthday (school closed)",
|
|
32 "2025-02-17": "President's Day (school closed)",
|
|
33 "2025-03-14": "No School (school closed)",
|
|
34 "2025-03-31": "Spring Recess (school closed)",
|
|
35 "2025-04-01": "Spring Recess (school closed)",
|
|
36 "2025-04-02": "Spring Recess (school closed)",
|
|
37 "2025-04-03": "Spring Recess (school closed)",
|
|
38 "2025-04-04": "Spring Recess (school closed)",
|
|
39 "2025-05-16": "Malcolm X's Birthday (school closed)",
|
|
40 "2025-05-26": "Memorial Day (school closed)",
|
|
41 }
|
34
|
42
|
|
43
|
46
|
44 def busdHoliday(s: datetime.datetime) -> str | None:
|
|
45 if s.weekday() > 4:
|
|
46 return 'weekend'
|
|
47 date = s.date().isoformat()
|
|
48 if date in holidays:
|
|
49 return holidays[date]
|
|
50 return None
|
|
51
|
|
52
|
47
|
53 codeVersion = 'auto-gen v4'
|
34
|
54 service = getCalendarService()
|
|
55
|
|
56 calIdForPerson = json.load(open('gcalendarwatch.conf'))['calId']
|
|
57
|
46
|
58 s = datetime.datetime(2024, 8, 14-1, 9, 0, 0, tzinfo=tzlocal.get_localzone())
|
|
59 while s < datetime.datetime(2025, 6, 5, tzinfo=tzlocal.get_localzone()):
|
34
|
60 s = s + datetime.timedelta(days=1)
|
46
|
61 for calId, school, startHM, endHM in [
|
|
62 (calIdForPerson['asher'], 'john muir', (9, 0), (15, 10)),
|
|
63 (calIdForPerson['ari'], 'BHS', (8, 30), (15, 33)),
|
34
|
64 ]:
|
46
|
65 if holiday := busdHoliday(s):
|
|
66 if holiday == 'weekend':
|
|
67 continue
|
|
68 event = {
|
|
69 'summary': holiday,
|
|
70 'description': codeVersion,
|
|
71 'start': {
|
|
72 'date': s.date().isoformat()
|
|
73 }, # allday
|
|
74 'end': {
|
|
75 'date': s.date().isoformat()
|
|
76 }, # allday
|
|
77 }
|
|
78 else:
|
|
79 summary = f'{school}'
|
|
80 if school == 'john muir' and ('2023-10-28' <= s.date().isoformat() <= '2023-10-31'):
|
|
81 summary += ' (shortened day)'
|
|
82 # if school == 'BHS' and ('2023-12-20' <= s.date().isoformat() <= '2023-12-22'):
|
|
83 # summary += ' (finals schedule)'
|
34
|
84
|
46
|
85 if school == 'BHS' and s.weekday() == 0:
|
35
|
86 startHM = (10, 0)
|
46
|
87
|
47
|
88 if school == 'john muir' and s.weekday() == 2:
|
|
89 endHM = (14, 15)
|
|
90
|
46
|
91 s = s.replace(hour=startHM[0], minute=startHM[1])
|
|
92 e = s.replace(hour=endHM[0], minute=endHM[1])
|
34
|
93
|
46
|
94 # schema: https://developers.google.com/calendar/api/v3/reference/events#resource-representations
|
|
95 event = {
|
|
96 'summary': summary,
|
|
97 'description': codeVersion,
|
|
98 'start': {
|
|
99 'dateTime': s.isoformat()
|
|
100 },
|
|
101 'end': {
|
|
102 'dateTime': e.isoformat()
|
|
103 },
|
|
104 }
|
|
105 print(calId, event)
|
34
|
106 # https://developers.google.com/calendar/api/v3/reference/events/insert
|
46
|
107 print(service.events().insert(calendarId=calId, body=event).execute())
|