Skip to content

Commit

Permalink
fix event list: configure all page queries, not just the first one
Browse files Browse the repository at this point in the history
When a large list of events was obtained, only the first query was correct. Subsequent queries used default parameters, so the resulting list always had the earliest events of the calendar, etc.
  • Loading branch information
kbulygin authored Aug 17, 2023
1 parent 30148bc commit 048f6ec
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions gcalcli/gcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,8 +1026,18 @@ def _iterate_events(self, start_datetime, event_list, year_date=False,

return selected

def _GetAllEvents(self, cal, events, end):

def _GetAllEvents(self, cal, start, end, search_text):
events = self._retry_with_backoff(
self.get_events()
.list(
calendarId=cal['id'],
timeMin=start.isoformat() if start else None,
timeMax=end.isoformat() if end else None,
q=search_text if search_text else None,
singleEvents=True
)
)

event_list = []

while 1:
Expand Down Expand Up @@ -1079,6 +1089,10 @@ def _GetAllEvents(self, cal, events, end):
self.get_events()
.list(
calendarId=cal['id'],
timeMin=start.isoformat() if start else None,
timeMax=end.isoformat() if end else None,
q=search_text if search_text else None,
singleEvents=True,
pageToken=pageToken
)
)
Expand All @@ -1091,17 +1105,7 @@ def _search_for_events(self, start, end, search_text):

event_list = []
for cal in self.cals:
events = self._retry_with_backoff(
self.get_events()
.list(
calendarId=cal['id'],
timeMin=start.isoformat() if start else None,
timeMax=end.isoformat() if end else None,
q=search_text if search_text else None,
singleEvents=True
)
)
event_list.extend(self._GetAllEvents(cal, events, end))
event_list.extend(self._GetAllEvents(cal, start, end, search_text))

event_list.sort(key=lambda x: x['s'])

Expand Down

0 comments on commit 048f6ec

Please sign in to comment.