view create_school_cals_2.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 f76f6368e2af
line wrap: on
line source

import datetime
import json
from pprint import pprint

import tzlocal

from calendar_connection import getCalendarService

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

service = getCalendarService()


def find(calId, s: datetime.datetime, e: datetime.datetime, summary: str):
    res = service.events().list(
        calendarId=calId,
        timeMin=s.isoformat(),
        timeMax=e.isoformat(),
        q=summary,
        maxResults=2500,
    ).execute()
    for item in res['items']:
        if item['summary'] != summary:
            continue
        yield item['id']


s = datetime.datetime(2023, 8, 1, tzinfo=tzlocal.get_localzone())
e = datetime.datetime(2024, 7, 1, tzinfo=tzlocal.get_localzone())
for id in find(calIdForPerson['ari'], s=s, e=e, summary="BHS 9"):
   service.events().delete(calendarId=calIdForPerson['ari'], eventId=id).execute()