A Go tool to delete spurious entries in Google Calendar created by mistake when importing iCalendar files.
- Go 1.25.0 or later
- Google Calendar API OAuth2 credentials
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Calendar API for your project:
- Go to APIs & Services → Library
- Search for "Google Calendar API"
- Click Enable
- Create OAuth2 credentials:
- Go to APIs & Services → Credentials
- Click Create Credentials → OAuth client ID
- Choose Desktop app as the application type
- Give it a name (e.g., "gcal-cleaner")
- Click Create
- Important: Configure the redirect URI:
- Click on your newly created OAuth client to edit it
- Under Authorized redirect URIs, add:
http://localhost:8080/callback - Click Save
- Download the credentials JSON file (click the download icon next to your OAuth client)
Export your OAuth2 credentials as an environment variable:
export GOOGLE_OAUTH_CREDENTIALS=$(cat /path/to/credentials.json)Or set it inline when running the command:
GOOGLE_OAUTH_CREDENTIALS=$(cat /path/to/credentials.json) ./gcal-cleaner -query "search term"go build -o gcal-cleanerOn the first run, the program will automatically open your browser for authorization:
./gcal-cleaner -query "search term"The program will:
- Automatically open your browser to the Google authorization page
- Start a local server on
http://localhost:8080to receive the callback - Wait for you to authorize the application
In your browser:
- Sign in with your Google account
- Grant access to the application
- You'll see "Authorization Successful!" in the browser
- The browser will automatically send the authorization code to the program
The authorization token will be saved to token.json for future use.
Note: If the browser doesn't open automatically, copy the URL from the terminal and paste it into your browser manually.
After the first authorization, you can run the program normally:
./gcal-cleaner -query "search term" [options]-query(required): Search query to filter events by summary or description-calendar: Calendar ID (default: "primary")-time-min: Minimum time for events (RFC3339 format, e.g., 2024-01-01T00:00:00Z)-time-max: Maximum time for events (RFC3339 format, e.g., 2024-12-31T23:59:59Z)
Search for events with "imported" in the summary or description:
./gcal-cleaner -query "imported"Search for events within a specific time range:
./gcal-cleaner -query "duplicate" -time-min "2024-01-01T00:00:00Z" -time-max "2024-12-31T23:59:59Z"Search in a specific calendar:
./gcal-cleaner -query "test" -calendar "[email protected]"- The tool authenticates with the Google Calendar API using OAuth2 credentials
- On first run, it will open a browser for you to authorize the application
- The authorization token is cached in
token.jsonfor future use - It searches for events matching your query in the specified calendar
- It displays all matching events with their details (summary, description, start time, ID)
- It prompts you for confirmation before deletion
- Upon confirmation (typing "yes" or "y"), it deletes the events one by one
- Requires explicit user confirmation before deleting any events
- Shows all events that will be deleted before proceeding
- Implements rate limiting with 100ms delay between deletions
- Reports success and failure counts after completion
- The query parameter searches both event summaries and descriptions
- Only single events are returned (recurring events are expanded)
- Events are ordered by start time for easier review
- The tool uses the "primary" calendar by default (usually your main Google Calendar)