Skip to content

Commit

Permalink
feat: all to filter annotations by companyId (scopes permitting)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Bush committed Sep 6, 2023
1 parent e937167 commit 4b0d2f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sypht/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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}
Expand All @@ -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."""
Expand All @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions sypht/util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import Any, Callable, Iterator, List

DEFAULT_REC_LIMIT = 100_000
Expand Down Expand Up @@ -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

0 comments on commit 4b0d2f7

Please sign in to comment.