61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Script to clear all events from all calendars in Google Calendar account
|
|
"""
|
|
import asyncio
|
|
import sys
|
|
import os
|
|
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"""
|
|
try:
|
|
service = await get_google_service()
|
|
|
|
# Get all calendars
|
|
print("Fetching calendar list...")
|
|
calendars_result = service.calendarList().list().execute()
|
|
calendars = calendars_result.get('items', [])
|
|
|
|
print(f"Raw calendars result: {calendars_result}")
|
|
print(f"Calendars list: {calendars}")
|
|
|
|
print(f"Found {len(calendars)} calendars to clear:")
|
|
|
|
for calendar in calendars:
|
|
calendar_id = calendar['id']
|
|
summary = calendar.get('summary', 'No summary')
|
|
primary = calendar.get('primary', False)
|
|
|
|
print(f" - {summary} (ID: {calendar_id}, Primary: {primary})")
|
|
|
|
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}")
|
|
|
|
except Exception as e:
|
|
print(f" ✗ Failed to clear {summary}: {e}")
|
|
|
|
print("\nAll calendars have been cleared of events.")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(clear_all_calendars()) |