Skip to content

Commit c928c89

Browse files
committed
chg: accunulate multiple params to list and logs
1 parent 6587901 commit c928c89

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

src/datasync/nva/nva_search_resources.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def search_resources_api(
6161
"""
6262
Get resources from NVA API
6363
64-
This will first fetch the data from the NVA API based on the search parameters
65-
then write the data to the specified S3 location
64+
This will use the NVA API to fetch resources based on the provided parameters.
65+
The data will be written to the specified S3 location in parquet format.
6666
6767
Args:
6868
resource_name: Will be used for the output files on S3, avoid using '-'.
@@ -91,7 +91,7 @@ def search_resources_api(
9191
# Filter by contributor and publication year:
9292
uv run datasync nva search-resources-api \
9393
--resource-name "author-publications" \
94-
--filter contributor="https://api.nva.unit.no/cristin/person/1773250" \\
94+
--filter contributor="https://api.nva.unit.no/cristin/person/1773250" \
9595
--filter publication_year_since=2020
9696
"""
9797
log.debug("Starting NVA API search with parameters", filters=filters)
@@ -119,7 +119,14 @@ def search_resources_api(
119119
log.error("Valid filters", valid_filters=VALID_PARAMS_NVA_API)
120120
raise typer.Exit(code=1)
121121

122-
search_params[key] = value
122+
if key in search_params:
123+
existing = search_params[key]
124+
if isinstance(existing, list):
125+
existing.append(value)
126+
else:
127+
search_params[key] = [existing, value]
128+
else:
129+
search_params[key] = value
123130
log.debug("Parsed search parameters", search_params=search_params)
124131
if not search_params:
125132
log.error("Valid filters", valid_filters=VALID_PARAMS_NVA_API)
@@ -143,7 +150,7 @@ def search_resources_api(
143150
)
144151

145152
log.info(f"Fetching resources from {base_url}")
146-
load_info = pipeline.run(
153+
pipeline.run(
147154
nva_search_source(
148155
base_url=base_url,
149156
resource_name=resource_name,
@@ -153,8 +160,6 @@ def search_resources_api(
153160
loader_file_format="parquet",
154161
)
155162

156-
log.info("Pipeline run completed", load_info=load_info)
157-
158163
if apply_filter:
159164
con = setup_duckdb_s3_connection(
160165
endpoint_url=storage_endpoint_url,
@@ -174,7 +179,6 @@ def search_resources_api(
174179
write_timestamp(con, storage_bucket, storage_prefix)
175180
con.close()
176181

177-
log.info("NVA data sync completed")
178182
log.info(
179183
f"Data available at: {storage_endpoint_url}/{storage_bucket}/{storage_prefix}/"
180184
f"main/{resource_name}.parquet"

src/datasync/nva/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
def get_nva_resources(
1515
client: RESTClient,
16-
search_params: dict[str, str],
16+
search_params: dict[str, str | list[str]],
1717
):
1818
"""
1919
Function to fetch resources from NVA search API.
@@ -38,7 +38,7 @@ def get_nva_resources(
3838
def nva_search_source(
3939
base_url: str,
4040
resource_name: str = "resources",
41-
search_params: dict[str, str] | None = None,
41+
search_params: dict[str, str | list[str]] | None = None,
4242
):
4343
"""
4444
DLT source for fetching resources from NVA search API.
@@ -203,5 +203,7 @@ def apply_filter_transformation(
203203
compression="zstd",
204204
overwrite=True,
205205
)
206-
207-
log.info("Filter applied and data written back to S3")
206+
log.info(
207+
"Filter applied and data written back to S3",
208+
number_of_resources=len(filtered_resources),
209+
)

0 commit comments

Comments
 (0)