def get_calendars(service: Resource) -> List[Dict]: calendars = [] request = service.calendarList().list(minAccessRole="writer", showHidden=True) while request is not None: calendars_result = request.execute() calendars.extend(calendars_result.get("items", [])) request = service.calendarList().list_next(request, calendars_result) return calendars
def get_calendar(service: Resource, calendar_name): if calendar_name == 'primary': # special case for just getting the primary calendar resp = service.calendarList().get(calendarId='primary').execute() return resp['id'] resp = service.calendarList().list().execute() for calendar in resp['items']: if calendar['summary'] == calendar_name: return calendar['id'] else: raise ValueError('Could not find calendar!')
def get_callendar_ids(allowed_calendars_ids: List[str], service: Resource) -> List: calendar_ids = [] while True: calendar_list = service.calendarList().list().execute() for calendar_list_entry in calendar_list["items"]: if ( not allowed_calendars_ids or calendar_list_entry["id"] in allowed_calendars_ids ): calendar_ids.append(calendar_list_entry["id"]) page_token = calendar_list.get("nextPageToken") if not page_token: break return calendar_ids