Skip to content

Commit

Permalink
Save 1 API call by re-using existing_events for removeCopiedEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
kaeff committed Sep 1, 2021
1 parent c96361e commit 88be2c7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def __init__(self, calendarId, googleService):
self.googleService = googleService

def copyAllEventsFrom(self, otherCalendar, period: DatePeriod, copySensibleData, colorId, skipMatching):
self.removeCopiedEvents(period)
events = otherCalendar.getEvents(period)
existing_events = self.getEvents(period)
self.removeCopiedEvents(existing_events)

for event in events:
if not skipMatching or not any(start_and_end_equal(event, e) for e in existing_events):
Expand All @@ -41,9 +41,9 @@ def getEvents(self, period: DatePeriod):
events = events_result.get('items', [])
return events

def removeCopiedEvents(self, period: DatePeriod):
def removeCopiedEvents(self, events):
eventsToRemove = list(
filter(lambda event: COPIED_EVENT_LEADING_TEXT in event.get('summary', ''), self.getEvents(period)))
filter(lambda event: COPIED_EVENT_LEADING_TEXT in event.get('summary', ''), events))
for event in eventsToRemove:
self.deleteEvent(event.get("id"))

Expand Down

0 comments on commit 88be2c7

Please sign in to comment.