Skip to content

Commit 1b0848f

Browse files
committed
refactoring: insertion files structure
1 parent 6cbec32 commit 1b0848f

5 files changed

Lines changed: 67 additions & 32 deletions

File tree

local_dev/tools/9d4dc6b920d1e2cc08a741f7c56821db.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

local_dev/tools/db-insertion/OpenAIRE/9d4dc6b920d1e2cc08a741f7c56821db.json

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"endpoint": "http://127.0.0.1:8081/dev/persistence/createVisualization/dev",
3+
"visualizations": [
4+
{
5+
"vis_id": "9d4dc6b920d1e2cc08a741f7c56821db",
6+
"vis_title": "openaire",
7+
"vis_clean_query": "DP0878177",
8+
"vis_query": "DP0878177",
9+
"vis_params": "{\"project_id\":\"DP0878177\",\"funder\":\"ARC\",\"acronym\":\"\",\"title\":\"Understanding the impact of global environmental change on Australian forests and woodlands using rainforest boundaries and Callitris growth as bio-indicators\",\"start_date\":\"2008-01-01\",\"end_date\":\"2011-12-31\",\"special_clause\":\"false\",\"oa_mandate\":\"false\",\"organisations\":[],\"openaire_link\":\"http:\\/\\/purl.org\\/au-research\\/grants\\/arc\\/DP0878177\",\"obj_id\":\"arc_________::fe52f7d04f4139c2c80b4144c294f12d\",\"call_id\":\"\",\"funding_tree\":[null,null,\"Discovery Projects\"]}",
10+
"data_file": "9d4dc6b920d1e2cc08a741f7c56821db.json"
11+
}
12+
]
13+
}
14+
15+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import json
2+
import requests
3+
4+
from pathlib import Path
5+
6+
# Before starting, you can change the path to the configuration for the desired integration and set of files.
7+
BASE_DIR = Path(__file__).resolve().parent
8+
CONFIG_PATH = BASE_DIR / "OpenAIRE" / "config.json" # Change integration folder name here.
9+
10+
# Fallbacks
11+
VISUALIZATION_DATA = []
12+
ENDPOINT_URL = "http://127.0.0.1:8081/dev/persistence/createVisualization/dev"
13+
14+
15+
def insert_from_config(config_path: Path) -> None:
16+
"""Insert visualizations described in the given config JSON file."""
17+
with open(config_path, "r") as f:
18+
config = json.load(f)
19+
20+
endpoint = config.get("endpoint", ENDPOINT_URL)
21+
visualizations = config.get("visualizations", VISUALIZATION_DATA)
22+
23+
for vis in visualizations:
24+
data_file = config_path.parent / vis["data_file"]
25+
with open(data_file, "r") as df:
26+
data = df.read()
27+
28+
payload = {
29+
"vis_id": vis["vis_id"],
30+
"vis_title": vis["vis_title"],
31+
"vis_clean_query": vis["vis_clean_query"],
32+
"vis_query": vis["vis_query"],
33+
"vis_params": vis["vis_params"],
34+
"data": data,
35+
}
36+
37+
res = requests.post(endpoint, json=payload)
38+
print(f"Inserted {vis['vis_id']}: {res.status_code}")
39+
print(res.text)
40+
41+
42+
def main() -> None:
43+
insert_from_config(CONFIG_PATH)
44+
45+
46+
if __name__ == "__main__":
47+
main()
48+
49+

local_dev/tools/insert_visualization.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)