view create_school_cals_2.py @ 49:2991c1166852

start calsync in go. Calendar list seems to sync
author drewp@bigasterisk.com
date Mon, 19 Aug 2024 13:25:03 -0700
parents f76f6368e2af
children c4230f701df9
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
        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['asher'], s=s, e=e, desc="auto-gen v3"):
    service.events().delete(calendarId=calIdForPerson['asher'], eventId=id).execute()