Last active
June 23, 2024 00:02
-
-
Save aloni636/0c75e54e3535b9ded556b3be06a8585f to your computer and use it in GitHub Desktop.
ICS Google-Calendar Unmerge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Added .ics file mistakenly to google calendar? Undo using this script. | |
# Iterate over all events and delete ones with icalUID which contains a unique identifier of events in the .ics file | |
# %% | |
# pip install gcsa | |
from gcsa.google_calendar import GoogleCalendar | |
from datetime import datetime | |
TARGET_GOOGLE_CALENDAR_NAME = None # None => default calender | |
ICALUID_IDENTIFIER = "some_name" # icalUID | |
gc = GoogleCalendar("your_google_address@gmail.com") | |
# %% | |
calendars = gc.get_calendar_list() | |
calendar_id = [c for c in calendars if c.description == TARGET_GOOGLE_CALENDAR_NAME][0].id | |
# %% | |
events_for_deletion = [e for e in gc.get_events(datetime.min, datetime.max, calendar_id=calendar_id) if ICALUID_IDENTIFIER in e.other['iCalUID']] | |
iter_len = len(events_for_deletion) | |
print(f"Process will delete {iter_len} events") | |
# %% | |
for i, e in enumerate(events_for_deletion): | |
print(f"{i+1}/{iter_len}: Deleting {e} for calender {TARGET_GOOGLE_CALENDAR_NAME}") | |
gc.delete_event(e.id, calendar_id=calendar_id) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment