From 94c5f0ac64399d263a9458679fad4043b35bbb72 Mon Sep 17 00:00:00 2001 From: Leo <5376265+leoherzog@users.noreply.github.com> Date: Tue, 25 May 2021 14:29:44 -0400 Subject: [PATCH] Remove Declined Events --- cal.30s.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cal.30s.py b/cal.30s.py index 8bc1eaf..a4471af 100755 --- a/cal.30s.py +++ b/cal.30s.py @@ -64,7 +64,7 @@ def main(): events = [] for cal in ids: thisCalInList = service.calendarList().get(calendarId=cal['id']).execute() # pylint: disable=no-member - thisCalsEvents = service.events().list(calendarId=cal['id'], timeMin=beginningOfDay, timeMax=endOfDay, maxResults=50, singleEvents=True).execute().get('items', []) # pylint: disable=no-member + thisCalsEvents = service.events().list(calendarId=cal['id'], timeMin=beginningOfDay, timeMax=endOfDay, maxResults=50, maxAttendees=1, singleEvents=True).execute().get('items', []) # pylint: disable=no-member for event in thisCalsEvents: event['summary'] = html.escape(event.get('summary', '')).replace('|', '∣') # reserved character for bitbar/argos. replace "vertical bar" with "divides" unicode character. event['icon'] = cal['icon'] @@ -76,11 +76,14 @@ def main(): event['color'] = colors.get('calendar', {}).get(thisCalInList.get('colorId')).get('background') events = events + thisCalsEvents - # sort by start time - events.sort(key = lambda event : event['start'].get('dateTime', event['start'].get('date'))) - # remove names in the filter events = [x for x in events if not x.get('summary') in eventNamesToFilter] + + # remove events that have been declined, if attendees key exists + events = [x for x in events if not x.get('attendees') or x.get('attendees')[0].get('responseStatus', '') != 'declined'] + + # sort by start time + events.sort(key = lambda event : event['start'].get('dateTime', event['start'].get('date'))) now = datetime.datetime.now().astimezone() @@ -210,4 +213,4 @@ def findMeetingId(text): return None if __name__ == '__main__': - main() \ No newline at end of file + main()