1717app = typer .Typer ()
1818
1919
20- # {
21- # "name": "projects",
22- # "endpoint": {
23- # "path": f"cristin/organization/{institution_code}/projects", # noqa: E501
24- # "data_selector": "hits",
25- # },
26- # }
27- # if projects
28- # else None,
29- # {
30- # "name": "persons",
31- # "endpoint": {
32- # "path": f"cristin/organization/{institution_code}/persons", # noqa: E501
33- # "data_selector": "hits",
34- # },
35- # }
36- # if persons
37- # else None,
38- # {
39- # "name": "categories",
40- # "endpoint": {
41- # "path": "cristin/category/project",
42- # "data_selector": "hits",
43- # },
44- # }
45- # if categories
46- # else None,
47- # {
48- # "name": "funding_sources",
49- # "endpoint": {
50- # "path": "cristin/funding-sources",
51- # "data_selector": "hits",
52- # },
53- # }
54- # if funding_sources
55- # else None,
20+ def get_funding_sources (client : RESTClient ):
21+ log .debug ("Fetching funding sources" )
22+ yield from client .paginate (
23+ "cristin/funding-sources" ,
24+ method = "get" ,
25+ )
5626
5727
58- @app .command ()
59- def run (
28+ def get_persons (client : RESTClient , institution_code : str ):
29+ log .debug ("Fetching persons" )
30+ yield from client .paginate (
31+ f"cristin/organization/{ institution_code } /persons" ,
32+ method = "get" ,
33+ )
34+
35+
36+ def get_projects (client : RESTClient , institution_code : str ):
37+ log .debug ("Fetching projects" )
38+ yield from client .paginate (
39+ f"cristin/organization/{ institution_code } /projects" ,
40+ method = "get" ,
41+ )
42+
43+
44+ def get_categories (client : RESTClient ):
45+ log .debug ("Fetching categories" )
46+ yield from client .paginate (
47+ "cristin/category/project" ,
48+ method = "get" ,
49+ )
50+
51+
52+ def get_resources (client : RESTClient , institution_code : str ):
53+ for year in set (range (1979 , datetime .datetime .now ().year + 1 )):
54+ log .debug ("Fetching resources for year" , year = year )
55+ yield from client .paginate (
56+ "search/resources" ,
57+ method = "get" ,
58+ params = {
59+ "unit" : institution_code ,
60+ "publicationYearSince" : year ,
61+ "publicationYearBefore" : year + 1 ,
62+ },
63+ )
64+
65+
66+ @dlt .source ()
67+ def nva (
68+ base_url : str = NVA_BASE_URL ,
69+ institution_code : str = INSTITUTION_CODE ,
6070 resources : bool = False ,
6171 projects : bool = False ,
6272 persons : bool = False ,
6373 categories : bool = False ,
6474 funding_sources : bool = False ,
65- base_url : str = NVA_BASE_URL ,
66- duckdb_name : str = NVA_DUCKDB_NAME ,
67- institution_code : str = INSTITUTION_CODE ,
6875):
69- @dlt .source ()
70- def nva ():
71- client = RESTClient (
72- base_url = base_url ,
73- paginator = JSONLinkPaginator (next_url_path = "nextResults" ),
74- data_selector = "hits" ,
75- )
76-
77- def get_resources ():
78- for year in set (range (2025 , datetime .datetime .now ().year + 1 )):
79- log .debug ("Fetching resources for year" , year = year )
80- yield from client .paginate (
81- "search/resources" ,
82- method = "get" ,
83- params = {
84- "unit" : institution_code ,
85- "publicationYearSince" : year ,
86- "publicationYearBefore" : year + 1 ,
87- },
88- )
76+ client = RESTClient (
77+ base_url = base_url ,
78+ paginator = JSONLinkPaginator (next_url_path = "nextResults" ),
79+ data_selector = "hits" ,
80+ )
8981
82+ if resources :
9083 yield dlt .resource (
9184 get_resources (),
9285 name = "resources" ,
9386 write_disposition = "replace" ,
9487 max_table_nesting = 1 ,
9588 )
9689
90+ if projects :
91+ yield dlt .resource (
92+ get_projects (client , institution_code ),
93+ name = "projects" ,
94+ write_disposition = "replace" ,
95+ max_table_nesting = 1 ,
96+ )
97+
98+ if persons :
99+ yield dlt .resource (
100+ get_persons (client , institution_code ),
101+ name = "persons" ,
102+ write_disposition = "replace" ,
103+ max_table_nesting = 1 ,
104+ )
105+ if categories :
106+ yield dlt .resource (
107+ get_categories (client ),
108+ name = "categories" ,
109+ write_disposition = "replace" ,
110+ max_table_nesting = 1 ,
111+ )
112+
113+ if funding_sources :
114+ yield dlt .resource (
115+ get_funding_sources (client ),
116+ name = "funding_sources" ,
117+ write_disposition = "replace" ,
118+ max_table_nesting = 1 ,
119+ )
120+
121+ return nva
122+
123+
124+ @app .command ()
125+ def run (
126+ resources : bool = False ,
127+ projects : bool = False ,
128+ persons : bool = False ,
129+ categories : bool = False ,
130+ funding_sources : bool = False ,
131+ base_url : str = NVA_BASE_URL ,
132+ duckdb_name : str = NVA_DUCKDB_NAME ,
133+ institution_code : str = INSTITUTION_CODE ,
134+ ):
97135 pipeline = dlt .pipeline (
98136 pipeline_name = duckdb_name ,
99137 destination = filesystem (
@@ -106,7 +144,19 @@ def get_resources():
106144 )
107145
108146 log .info (
109- pipeline .run (nva (), write_disposition = "replace" , loader_file_format = "parquet" )
147+ pipeline .run (
148+ nva (
149+ base_url = base_url ,
150+ institution_code = institution_code ,
151+ resources = resources ,
152+ projects = projects ,
153+ persons = persons ,
154+ categories = categories ,
155+ funding_sources = funding_sources ,
156+ ),
157+ write_disposition = "replace" ,
158+ loader_file_format = "parquet" ,
159+ )
110160 )
111161
112162
0 commit comments