From 9cf4fab4dc9e1645c54ef8a6ff88dd3772f87514 Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Thu, 1 Feb 2024 09:12:47 -0700 Subject: [PATCH 1/2] docs: pagination example --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 0f78ef9..0f34510 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,28 @@ def get_tasks_sync(): print(error) ``` +Example of paginating through completed project tasks: + +```python +def get_all_completed_items(original_params: dict): + params = original_params.copy() + results = [] + + while True: + response = api.get_completed_items(**(params | {"limit": 100})) + results.append(response.items) + + if not response.has_more: + break + + params["cursor"] = response.next_cursor + + # flatten the results + return [item for sublist in results for item in sublist] + +items = get_all_completed_items({"project_id": 123}) +``` + ### Documentation For more detailed reference documentation, have a look at the [API documentation with Python examples](https://developer.todoist.com/rest/v2/?python). From 1a55f7e7578e9388dcff6fb52c45381600bc4dd7 Mon Sep 17 00:00:00 2001 From: Andrew Mleczko Date: Tue, 7 May 2024 15:36:42 +0200 Subject: [PATCH 2/2] small typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f34510..f4a8da3 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ def get_tasks_sync(): print(error) ``` -Example of paginating through completed project tasks: +Example of paginating through a completed project tasks: ```python def get_all_completed_items(original_params: dict):