view create_school_cals.py @ 83:7f50e5bb30f5

ide
author drewp@bigasterisk.com
date Sat, 07 Sep 2024 16:12:15 -0700
parents f76f6368e2af
children
line wrap: on
line source

import datetime
import json
from pprint import pprint

import tzlocal

from calendar_connection import getCalendarService

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 v4'
service = getCalendarService()

calIdForPerson = json.load(open('gcalendarwatch.conf'))['calId']

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, startHM, endHM in [
        (calIdForPerson['asher'], 'john muir', (9, 0), (15, 10)),
        (calIdForPerson['ari'], 'BHS', (8, 30), (15, 33)),
    ]:
        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)'

            if school == 'BHS' and s.weekday() == 0:
                startHM = (10, 0)

            if school == 'john muir' and s.weekday() == 2:
                endHM = (14, 15)

            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': 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())