Skip to content
Snippets Groups Projects
json_demo.py 933 B
Newer Older
Große, Judith's avatar
Große, Judith committed
#!/usr/bin/env python3
import json
from input_fj import input

def output_to_json(V,E):
    list_of_node_dicts = list()
    list_of_edge_dicts = list()
    dict_of_all = dict()
    for node in V:
        new_dict = dict()
        new_dict["name"] = node.title
        new_dict["author"] = node.contributors
        new_dict["year"] = node.publication_date
        new_dict["doi"] = node.doi_url
        
        
        list_of_node_dicts.append(new_dict)
    for edge in E:
        new_dict_2 = dict()
        new_dict_2["source"] = edge[0]
        new_dict_2["target"] = edge[1]
        list_of_edge_dicts.append(new_dict_2)
    dict_of_all["nodes"] = list_of_node_dicts
    dict_of_all["links"] = list_of_edge_dicts
    #return(dict_of_all)
    with open('json_text.txt','w') as outfile:
        json.dump(dict_of_all, outfile)
  

#knoten = ["doi1", "doi2", "doi3"]
#kanten = [[1,2],[3,4],[5,6]]
#output_to_json(knoten,kanten)