From 4b0d2f7a5d132053b493071f174cc2faed9a5e58 Mon Sep 17 00:00:00 2001 From: Daniel Bush Date: Wed, 6 Sep 2023 15:14:48 +1000 Subject: [PATCH] feat: all to filter annotations by companyId (scopes permitting) --- sypht/client.py | 5 +++++ sypht/util.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/sypht/client.py b/sypht/client.py index 1d0c6a0..849fa57 100644 --- a/sypht/client.py +++ b/sypht/client.py @@ -419,6 +419,7 @@ def get_annotations( to_date=None, endpoint=None, rec_limit=None, + company_id=None, ): page_iter = fetch_all_pages( name="get_annotations", @@ -435,6 +436,7 @@ def get_annotations( from_date=from_date, to_date=to_date, endpoint=endpoint, + company_id=company_id, ): annotations.extend(response["annotations"]) return {"annotations": annotations} @@ -448,6 +450,7 @@ def _get_annotations( from_date=None, to_date=None, endpoint=None, + company_id=None, offset=0, ): """Fetch a single page of annotations skipping the given offset number of pages first. Use get_annotations to fetch all pages.""" @@ -464,6 +467,8 @@ def _get_annotations( filters.append("fromDate=" + from_date) if to_date is not None: filters.append("toDate=" + to_date) + if company_id is not None: + filters.append("companyId=" + company_id) endpoint = urljoin( endpoint or self.base_endpoint, ("/app/annotations?" + "&".join(filters)) diff --git a/sypht/util.py b/sypht/util.py index cd27a2c..d412a7d 100644 --- a/sypht/util.py +++ b/sypht/util.py @@ -1,3 +1,4 @@ +import logging from typing import Any, Callable, Iterator, List DEFAULT_REC_LIMIT = 100_000 @@ -48,6 +49,9 @@ def fetch_all_pages(*args, **kwargs) -> Iterator[Any]: if len(page) == 0: break recs += len(page) + logging.info( + f"fetch_all_pages({name}): fetched page {page_count} (records={recs})" + ) yield response return fetch_all_pages