Fix recurring event duplication - handle recurringEventId properly in all phases

This commit is contained in:
root
2025-10-23 18:46:49 +00:00
parent da2b9960b0
commit db1206f91c
2 changed files with 51 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
Script to clear all events from all calendars in Google Calendar account
Script to delete all calendars from Google Calendar account
"""
import asyncio
import sys
@@ -9,8 +9,8 @@ sys.path.append('.')
from steps.advoware_cal_sync.calendar_sync_event_step import get_google_service
async def clear_all_calendars():
"""Clear all events from all calendars"""
async def delete_all_calendars():
"""Delete all calendars from the Google account"""
try:
service = await get_google_service()
@@ -22,7 +22,7 @@ async def clear_all_calendars():
print(f"Raw calendars result: {calendars_result}")
print(f"Calendars list: {calendars}")
print(f"Found {len(calendars)} calendars to clear:")
print(f"Found {len(calendars)} calendars to delete:")
for calendar in calendars:
calendar_id = calendar['id']
@@ -31,31 +31,22 @@ async def clear_all_calendars():
print(f" - {summary} (ID: {calendar_id}, Primary: {primary})")
# Skip primary calendar if you want to keep it
if primary:
print(f" Skipping primary calendar: {summary}")
continue
try:
# Get all events in this calendar
events_result = service.events().list(calendarId=calendar_id, singleEvents=True).execute()
events = events_result.get('items', [])
print(f" Found {len(events)} events to delete")
# Delete each event
deleted_count = 0
for event in events:
try:
service.events().delete(calendarId=calendar_id, eventId=event['id']).execute()
deleted_count += 1
except Exception as e:
print(f" Failed to delete event {event['id']}: {e}")
print(f" ✓ Deleted {deleted_count} events from: {summary}")
# Delete the calendar
service.calendars().delete(calendarId=calendar_id).execute()
print(f" ✓ Deleted calendar: {summary}")
except Exception as e:
print(f" ✗ Failed to clear {summary}: {e}")
print(f" ✗ Failed to delete calendar {summary}: {e}")
print("\nAll calendars have been cleared of events.")
print("\nAll non-primary calendars have been deleted.")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
asyncio.run(clear_all_calendars())
asyncio.run(delete_all_calendars())