changeset 46:a53d79faac16

new school year
author drewp@bigasterisk.com
date Wed, 07 Aug 2024 00:08:56 -0700
parents e53a1bc87f99
children f76f6368e2af
files create_school_cals.py
diffstat 1 files changed, 84 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/create_school_cals.py	Thu Jun 06 15:57:26 2024 -0700
+++ b/create_school_cals.py	Wed Aug 07 00:08:56 2024 -0700
@@ -6,76 +6,99 @@
 
 from calendar_connection import getCalendarService
 
-
-def busdHoliday(s: datetime.datetime) -> bool:
-    if s.weekday() > 4:
-        return True
-    date = s.date().isoformat()
-    if date in {
-            '2023-09-04',
-            '2023-10-09',
-            '2023-10-27',
-            '2023-11-10',
-            '2024-01-15',
-            '2024-01-29',
-            '2024-02-16',
-            '2024-02-19',
-            '2024-05-17',
-            '2024-05-27',
-    }:
-        return True
-    if '2023-11-20' <= date <= '2023-11-24':
-        return True
-    if '2023-12-25' <= date <= '2024-01-05':
-        return True
-    if '2024-04-01' <= date <= '2024-04-05':
-        return True
-    return False
+holidays = {
+    "2024-09-02": "Labor Day (school closed)",
+    "2024-10-07": "Staff Development (school closed)",
+    "2024-11-01": "Confs. & Staff Dev. (school closed)",
+    "2024-11-11": "Veteran's Day (school closed)",
+    "2024-11-25": "Thanksgiving Break (school closed)",
+    "2024-11-26": "Thanksgiving Break (school closed)",
+    "2024-11-27": "Thanksgiving Break (school closed)",
+    "2024-11-28": "Thanksgiving Break (school closed)",
+    "2024-11-29": "Thanksgiving Break (school closed)",
+    "2024-12-23": "Winter Recess (school closed)",
+    "2024-12-24": "Winter Recess (school closed)",
+    "2024-12-25": "Winter Recess (school closed)",
+    "2024-12-26": "Winter Recess (school closed)",
+    "2024-12-27": "Winter Recess (school closed)",
+    "2024-12-30": "Winter Recess (school closed)",
+    "2024-12-31": "Winter Recess (school closed)",
+    "2025-01-01": "Winter Recess (school closed)",
+    "2025-01-02": "Winter Recess (school closed)",
+    "2025-01-03": "Winter Recess (school closed)",
+    "2025-01-20": "MLK's Birthday (school closed)",
+    "2025-01-27": "Staff Development Day (school closed)",
+    "2025-02-14": "Lincoln's Birthday (school closed)",
+    "2025-02-17": "President's Day (school closed)",
+    "2025-03-14": "No School (school closed)",
+    "2025-03-31": "Spring Recess (school closed)",
+    "2025-04-01": "Spring Recess (school closed)",
+    "2025-04-02": "Spring Recess (school closed)",
+    "2025-04-03": "Spring Recess (school closed)",
+    "2025-04-04": "Spring Recess (school closed)",
+    "2025-05-16": "Malcolm X's Birthday (school closed)",
+    "2025-05-26": "Memorial Day (school closed)",
+}
 
 
+def busdHoliday(s: datetime.datetime) -> str | None:
+    if s.weekday() > 4:
+        return 'weekend'
+    date = s.date().isoformat()
+    if date in holidays:
+        return holidays[date]
+    return None
+
+
+codeVersion = 'auto-gen v3'
 service = getCalendarService()
 
 calIdForPerson = json.load(open('gcalendarwatch.conf'))['calId']
 
-s = datetime.datetime(2023, 8, 16, 9, 0, 0, tzinfo=tzlocal.get_localzone())
-while s < datetime.datetime(2024, 6, 4, tzinfo=tzlocal.get_localzone()):
+s = datetime.datetime(2024, 8, 14-1, 9, 0, 0, tzinfo=tzlocal.get_localzone())
+while s < datetime.datetime(2025, 6, 5, tzinfo=tzlocal.get_localzone()):
     s = s + datetime.timedelta(days=1)
-    for calId, school, grade, startHM in [
-        (calIdForPerson['twins'], 'john muir', 'K', (9, 10)),
-        (calIdForPerson['asher'], 'john muir', '2', (9, 0)),
-        (calIdForPerson['ari'], 'BHS', '9th', (8, 30)),
+    for calId, school, startHM, endHM in [
+        (calIdForPerson['asher'], 'john muir', (9, 0), (15, 10)),
+        (calIdForPerson['ari'], 'BHS', (8, 30), (15, 33)),
     ]:
-        if busdHoliday(s):
-            continue
-        summary = f'{school} {grade}'
-        if school == 'john muir' and ('2023-10-23' <= s.date().isoformat() <= '2023-10-26'):
-            summary += ' (shortened day)'
-        if school == 'BHS' and ('2023-12-20' <= s.date().isoformat() <= '2023-12-22'):
-            summary += ' (finals schedule)'
+        if holiday := busdHoliday(s):
+            if holiday == 'weekend':
+                continue
+            event = {
+                'summary': holiday,
+                'description': codeVersion,
+                'start': {
+                    'date': s.date().isoformat()
+                },  # allday
+                'end': {
+                    'date': s.date().isoformat()
+                },  # allday
+            }
+        else:
+            summary = f'{school}'
+            if school == 'john muir' and ('2023-10-28' <= s.date().isoformat() <= '2023-10-31'):
+                summary += ' (shortened day)'
+            # if school == 'BHS' and ('2023-12-20' <= s.date().isoformat() <= '2023-12-22'):
+            #     summary += ' (finals schedule)'
 
-        endHM = (23, 59)
-        if grade == 'K':
-            endHM = (14, 15)
-        elif grade == '2':
-            endHM = (14, 15) if s.weekday() == 2 else (15, 10)
-        elif grade == '9th':
-            endHM = (14, 50) if s.weekday() == 2 else (15, 30)
-            if s.weekday() == 0:
+            if school == 'BHS' and s.weekday() == 0:
                 startHM = (10, 0)
-        s = s.replace(hour=startHM[0], minute=startHM[1])
-        e = s.replace(hour=endHM[0], minute=endHM[1])
+
+            s = s.replace(hour=startHM[0], minute=startHM[1])
+            e = s.replace(hour=endHM[0], minute=endHM[1])
 
-        # schema: https://developers.google.com/calendar/api/v3/reference/events#resource-representations
-        event = {
-            'summary': summary,
-            'description': 'auto-gen v2',
-            'start': {
-                'dateTime': s.isoformat()
-            },
-            'end': {
-                'dateTime': e.isoformat()
-            },
-        }
-        print(event)
+            # schema: https://developers.google.com/calendar/api/v3/reference/events#resource-representations
+            event = {
+                'summary': summary,
+                'description': codeVersion,
+                'start': {
+                    'dateTime': s.isoformat()
+                },
+                'end': {
+                    'dateTime': e.isoformat()
+                },
+            }
+        print(calId, event)
         # https://developers.google.com/calendar/api/v3/reference/events/insert
-        print(service.events().insert(calendarId=calId, body=event).execute())
\ No newline at end of file
+        print(service.events().insert(calendarId=calId, body=event).execute())