-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extensions to aaq, flow_results.
- Loading branch information
Showing
11 changed files
with
90 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from collections.abc import Iterator | ||
|
||
from httpx import Client | ||
|
||
|
||
def get_paginated( | ||
client: Client, | ||
url: str, | ||
**kwargs: str | int, | ||
) -> Iterator[dict]: | ||
"""Paginate over pages in an AAQ endpoint up to a limit.""" | ||
|
||
limit: int = 100 | ||
offset: int = 0 | ||
|
||
params = {"offset": offset, "limit": limit} | ||
|
||
while True: | ||
print( | ||
"Retrieving results for offsets: ", | ||
params["offset"], | ||
"to", | ||
params["offset"] + limit, | ||
sep=" ", | ||
) | ||
# Need {**params, **kwargs}. mypy dislikes str|int for lines 27, 40. | ||
response = client.get(url, params={**params, **kwargs}) | ||
response.raise_for_status() | ||
|
||
result: list[dict] = response.json()["result"] | ||
yield from result | ||
|
||
if len(result) < limit: | ||
return | ||
else: | ||
params["offset"] += limit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Directory ‘/home/schalk/reach/rdw-ingestion-tools/rdw_ingestion_tools/api/flow_results/extensions/’ does not exist; create? (y or n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from collections.abc import Iterator | ||
|
||
from httpx import Client | ||
|
||
|
||
def get_ids(client: Client, **kwargs: str | int) -> Iterator[str]: | ||
"""Returns a list of flow id's. | ||
These id's are required in order to get responses from the Flow | ||
Results API. | ||
""" | ||
|
||
params = {**kwargs} | ||
url = "" | ||
|
||
response = client.get(url, params=params) | ||
response.raise_for_status() | ||
|
||
for flow in response.json()["data"]: | ||
yield flow["id"] | ||
|
||
|
||
def get_paginated( | ||
client: Client, url: str, **kwargs: str | int | ||
) -> Iterator[list]: | ||
"""Paginate over the Flow Results Responses Endpoint. | ||
Each response returns a next link which is followed until | ||
the full result set is returned. | ||
""" | ||
|
||
while True: | ||
response = client.get(url, params={**kwargs}) | ||
response.raise_for_status() | ||
|
||
data: dict = response.json()["data"] | ||
|
||
results: list = data["attributes"]["responses"] | ||
yield from results | ||
|
||
try: | ||
full_url = data["relationships"]["links"]["next"] | ||
url = full_url.split("packages/")[-1] | ||
except AttributeError: | ||
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters