Mercurial > code > home > repos > gcalendarwatch
view create_school_cals.py @ 43:b5d3d9a8c83d
new graph of just the events happening now
author | drewp@bigasterisk.com |
---|---|
date | Mon, 19 Feb 2024 13:53:46 -0800 |
parents | 6d602c53eb33 |
children | a53d79faac16 |
line wrap: on
line source
import datetime import json from pprint import pprint import tzlocal 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 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 = 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)), ]: 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)' 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: startHM = (10, 0) 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) # https://developers.google.com/calendar/api/v3/reference/events/insert print(service.events().insert(calendarId=calId, body=event).execute())