From c1faf0a8e388dfc13af392575363ed7acdaf75b0 Mon Sep 17 00:00:00 2001 From: Tommy Au <75346987+smarttommyau@users.noreply.github.com> Date: Tue, 26 Dec 2023 04:58:26 +0800 Subject: [PATCH] Allow passing starting cursor in paginated helper (#222) * Allow passing starting cursor in paginated helper Allow passing next_cursor to the paginated api to set the starting cursor. * Take a slightly different approach --------- Co-authored-by: ramnes --- notion_client/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notion_client/helpers.py b/notion_client/helpers.py index 7b339f5..2b44bab 100644 --- a/notion_client/helpers.py +++ b/notion_client/helpers.py @@ -30,7 +30,7 @@ def iterate_paginated_api( function: Callable[..., Any], **kwargs: Any ) -> Generator[List[Any], None, None]: """Return an iterator over the results of any paginated Notion API.""" - next_cursor = None + next_cursor = kwargs.pop("start_cursor", None) while True: response = function(**kwargs, start_cursor=next_cursor) @@ -53,7 +53,7 @@ async def async_iterate_paginated_api( function: Callable[..., Awaitable[Any]], **kwargs: Any ) -> AsyncGenerator[List[Any], None]: """Return an async iterator over the results of any paginated Notion API.""" - next_cursor = None + next_cursor = kwargs.pop("start_cursor", None) while True: response = await function(**kwargs, start_cursor=next_cursor)