1+ from collections import defaultdict
2+
13import typer
24
35from ..settings import (
@@ -61,8 +63,8 @@ def search_resources_api(
6163 """
6264 Get resources from NVA API
6365
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
66+ This will use the NVA API to fetch resources based on the provided parameters.
67+ The data will be written to the specified S3 location in parquet format.
6668
6769 Args:
6870 resource_name: Will be used for the output files on S3, avoid using '-'.
@@ -91,7 +93,7 @@ def search_resources_api(
9193 # Filter by contributor and publication year:
9294 uv run datasync nva search-resources-api \
9395 --resource-name "author-publications" \
94- --filter contributor="https://api.nva.unit.no/cristin/person/1773250" \\
96+ --filter contributor="https://api.nva.unit.no/cristin/person/1773250" \
9597 --filter publication_year_since=2020
9698 """
9799 log .debug ("Starting NVA API search with parameters" , filters = filters )
@@ -109,7 +111,7 @@ def search_resources_api(
109111 "in the output file names due to DLT naming conventions."
110112 )
111113
112- search_params = {}
114+ search_params : defaultdict [ str , list [ str ]] = defaultdict ( list )
113115 for filter_str in filters :
114116 key , value = filter_str .split ("=" , 1 )
115117 key = key .strip ()
@@ -119,7 +121,8 @@ def search_resources_api(
119121 log .error ("Valid filters" , valid_filters = VALID_PARAMS_NVA_API )
120122 raise typer .Exit (code = 1 )
121123
122- search_params [key ] = value
124+ search_params [key ].append (value )
125+
123126 log .debug ("Parsed search parameters" , search_params = search_params )
124127 if not search_params :
125128 log .error ("Valid filters" , valid_filters = VALID_PARAMS_NVA_API )
@@ -143,7 +146,7 @@ def search_resources_api(
143146 )
144147
145148 log .info (f"Fetching resources from { base_url } " )
146- load_info = pipeline .run (
149+ pipeline .run (
147150 nva_search_source (
148151 base_url = base_url ,
149152 resource_name = resource_name ,
@@ -153,8 +156,6 @@ def search_resources_api(
153156 loader_file_format = "parquet" ,
154157 )
155158
156- log .info ("Pipeline run completed" , load_info = load_info )
157-
158159 if apply_filter :
159160 con = setup_duckdb_s3_connection (
160161 endpoint_url = storage_endpoint_url ,
@@ -174,7 +175,6 @@ def search_resources_api(
174175 write_timestamp (con , storage_bucket , storage_prefix )
175176 con .close ()
176177
177- log .info ("NVA data sync completed" )
178178 log .info (
179179 f"Data available at: { storage_endpoint_url } /{ storage_bucket } /{ storage_prefix } /"
180180 f"main/{ resource_name } .parquet"
0 commit comments