-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_correspondence.py
33 lines (26 loc) · 952 Bytes
/
create_correspondence.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#curl -H "X-Dataverse-key: $API_TOKEN" -X POST http://$SERVER/api/datasets/$id/move/$alias
from pyDataverse.api import NativeApi, DataAccessApi
import json
from config import Config
config = Config()
def find_correspondence(tree, parent, d):
for data in tree:
if data["type"] == "dataset":
d[data['dataset_id']] = parent
if data["type"] == "dataverse":
if "children" in data:
if len(data["children"]) > 0:
d = find_correspondence(data["children"], data["dataverse_alias"],d)
return d
def main():
resp = config.api_origin.get_children(":root", "dataverse", ["dataverses", "datasets"])
print(resp)
print(len(resp))
d = {}
d = find_correspondence(resp, ":root", d)
print(d)
print(len(d))
with open('correspondence.json', 'w') as outfile:
json.dump(d, outfile, indent=4, sort_keys=True)
if __name__ == "__main__":
main()