Skip to content

Instantly share code, notes, and snippets.

@Waffleboy
Created July 1, 2018 14:16
Show Gist options
  • Save Waffleboy/8d3f3fdbc83febeee82bbe8b04dacd7e to your computer and use it in GitHub Desktop.
Save Waffleboy/8d3f3fdbc83febeee82bbe8b04dacd7e to your computer and use it in GitHub Desktop.
Delete birthday events from google calendar
"""
I was really annoyed when facebook synced birthdays to google calendar as events which filled up the entire calendar
with no easy way to delete/hide them.
This script does exactly that.
"""
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
import datetime
# See step 1 of https://developers.google.com/calendar/quickstart/python
credentials_json_filepath = '/storage/Downloads/client_secret.json'
# Setup the Calendar API - https://developers.google.com/calendar/quickstart/python
def obtain_service():
SCOPES = 'https://www.googleapis.com/auth/calendar'
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets(credentials_json_filepath, SCOPES)
creds = tools.run_flow(flow, store)
service = build('calendar', 'v3', http=creds.authorize(Http()))
return service
def is_birthday_event(event):
return 'birthday' in event['summary'].lower()
service = obtain_service()
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
service_events = service.events()
# get up to 1000 events from now
events_result = service_events.list(calendarId='primary', timeMin=now,
maxResults=1000, singleEvents=True,
orderBy='startTime').execute()
events = events_result.get('items', [])
# delete them - https://developers.google.com/calendar/v3/reference/events/delete
for event in events:
if is_birthday_event(event):
response = service_events.delete(calendarId='primary',eventId=event['id']).execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment