#!/usr/bin/env python3 """ Delete duplicate calendar events based on screenshot Manually delete the duplicate events that were created during live score updates """ from google.oauth2 import service_account from googleapiclient.discovery import build from datetime import datetime, timedelta import pytz import sys def authenticate(credentials_file='credentials.json'): """Authenticate with Google Calendar using service account credentials""" try: credentials = service_account.Credentials.from_service_account_file( credentials_file, scopes=['https://www.googleapis.com/auth/calendar'] ) service = build('calendar', 'v3', credentials=credentials) print(f"✓ Successfully authenticated with Google Calendar") return service except Exception as e: print(f"✗ Authentication failed: {e}") sys.exit(1) def delete_specific_events(service, calendar_id='primary'): """Delete specific duplicate events based on partial scores""" # Based on the screenshot, these are the duplicate events to look for: duplicates_to_find = [ ("1-0", "NGX", "Liquid"), # 19:00 1-0 NGX vs Liquid ("1-1", "NGX", "Liquid"), # 19:45 1-1 NGX vs Liquid ] # Get events for Sept 5 target_date = datetime(2025, 9, 5, tzinfo=pytz.UTC) time_min = target_date.isoformat() time_max = (target_date + timedelta(days=1)).isoformat() events_result = service.events().list( calendarId=calendar_id, timeMin=time_min, timeMax=time_max, maxResults=500, singleEvents=True, orderBy='startTime' ).execute() events = events_result.get('items', []) print(f"\nScanning {len(events)} events on September 5th...") print("=" * 60) events_to_delete = [] for event in events: summary = event.get('summary', '') # Check if this matches any of our duplicate patterns for score, team1, team2 in duplicates_to_find: if score in summary and team1 in summary and team2 in summary and '✓' not in summary: events_to_delete.append({ 'id': event['id'], 'summary': summary, 'start': event['start'].get('dateTime', event['start'].get('date')) }) print(f"Found duplicate: {summary}") print(f" Time: {event['start'].get('dateTime', event['start'].get('date'))}") print(f" ID: {event['id']}") break if not events_to_delete: print("\n❌ No duplicate events found in API.") print("This could mean:") print("1. The duplicates are in a different calendar") print("2. They have already been deleted") print("3. The calendar interface is showing cached data") print("\nTry refreshing your browser (Ctrl+F5 or Cmd+Shift+R)") return print(f"\n⚠️ Found {len(events_to_delete)} duplicate events to delete") print("-" * 60) # Confirm before deleting print("\nThese events will be deleted:") for event in events_to_delete: print(f" - {event['summary']} at {event['start'][:19]}") response = input("\nDo you want to delete these events? (yes/no): ") if response.lower() == 'yes': deleted_count = 0 for event in events_to_delete: try: service.events().delete( calendarId=calendar_id, eventId=event['id'] ).execute() print(f"✓ Deleted: {event['summary']}") deleted_count += 1 except Exception as e: print(f"✗ Failed to delete {event['summary']}: {e}") print(f"\n✓ Successfully deleted {deleted_count} duplicate events") else: print("\n❌ Deletion cancelled") def main(): # Authenticate service = authenticate() # Delete specific duplicates delete_specific_events(service) print("\nPlease refresh your Google Calendar to see the changes.") print("If you still see duplicates, they might be in a different calendar.") if __name__ == "__main__": main()