comparison create_school_cals.py @ 46:a53d79faac16

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