view create_school_cals_2.py @ 83:7f50e5bb30f5

ide
author drewp@bigasterisk.com
date Sat, 07 Sep 2024 16:12:15 -0700
parents c4230f701df9
children
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, desc: str):
    res = service.events().list(
        calendarId=calId,
        timeMin=s.isoformat(),
        timeMax=e.isoformat(),
        q=desc,
        maxResults=2500,
    ).execute()
    for item in res['items']:
        if item['description'] != desc:
            continue
        dt = datetime.datetime.strptime(item['start']['dateTime'], '%Y-%m-%dT%H:%M:%S%z')
        if dt.weekday() != 1: 
            continue
        yield item['id']


s = datetime.datetime(2024, 8, 1, tzinfo=tzlocal.get_localzone())
e = datetime.datetime(2025, 7, 1, tzinfo=tzlocal.get_localzone())
for id in find(calIdForPerson['ari'], s=s, e=e, desc="auto-gen v5"):
    print(id)
    service.events().delete(calendarId=calIdForPerson['ari'], eventId=id).execute()