Skip to content

Commit 491985d

Browse files
committed
get all publications per year instead, move rest_api_source to a function
1 parent 2ac3e0e commit 491985d

1 file changed

Lines changed: 46 additions & 14 deletions

File tree

src/datasync/nva.py

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from .settings import (
66
INSTITUTION_CODE,
7-
INSTITUTION_NAME,
87
NVA_BASE_URL,
98
NVA_DUCKDB_NAME,
109
log,
@@ -13,19 +12,29 @@
1312
app = typer.Typer()
1413

1514

16-
@app.command()
17-
def run(
18-
resources: bool = False,
19-
projects: bool = False,
20-
persons: bool = False,
21-
categories: bool = False,
22-
funding_sources: bool = False,
23-
base_url: str = NVA_BASE_URL,
24-
duckdb_name: str = NVA_DUCKDB_NAME,
25-
institution_name: str = INSTITUTION_NAME,
26-
institution_code: str = INSTITUTION_CODE,
15+
def dlt_source(
16+
year,
17+
resources,
18+
projects,
19+
persons,
20+
categories,
21+
funding_sources,
22+
base_url,
23+
institution_code,
2724
):
28-
source = rest_api_source(
25+
if year is None:
26+
log.info("No year specified, syncing all available years.")
27+
resource_params = {
28+
"unit": institution_code,
29+
}
30+
else:
31+
log.info(f"Syncing data for year: {year}")
32+
resource_params = {
33+
"unit": institution_code,
34+
"publicationYearSince": year,
35+
"publicationYearBefore": year + 1,
36+
}
37+
return rest_api_source(
2938
{
3039
"client": {
3140
"base_url": base_url,
@@ -44,7 +53,7 @@ def run(
4453
"path": "search/resources",
4554
"data_selector": "hits",
4655
"params": {
47-
"institution": institution_name,
56+
**resource_params,
4857
},
4958
},
5059
}
@@ -92,12 +101,35 @@ def run(
92101
}
93102
)
94103

104+
105+
@app.command()
106+
def run(
107+
resources: bool = False,
108+
projects: bool = False,
109+
persons: bool = False,
110+
categories: bool = False,
111+
funding_sources: bool = False,
112+
base_url: str = NVA_BASE_URL,
113+
duckdb_name: str = NVA_DUCKDB_NAME,
114+
institution_code: str = INSTITUTION_CODE,
115+
year: int = None,
116+
):
95117
pipeline = dlt.pipeline(
96118
pipeline_name=duckdb_name,
97119
destination="duckdb",
98120
dataset_name="main",
99121
)
100122

123+
source = dlt_source(
124+
year=year,
125+
resources=resources,
126+
projects=projects,
127+
persons=persons,
128+
categories=categories,
129+
funding_sources=funding_sources,
130+
base_url=base_url,
131+
institution_code=institution_code,
132+
)
101133
log.info(pipeline.run(source))
102134

103135

0 commit comments

Comments
 (0)