-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (33 loc) · 1.34 KB
/
main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
from helpers import drawer_pyvis, file_helper
# TODO add tracking of how the graph has grown over time
data_file_path = "data/data.json"
def add_node(data, name):
data["nodes"].append(name)
def add_edge(data, edge):
# TODO ensure edge is valid (both nodes exist)
data["edges"].append(edge)
if __name__ == '__main__':
print("Welcome to your knowledge graph <3")
print("Commands: 'n' for new node, 'e' for new edge, 'l' for load visuals, 's' for save & exit")
data = file_helper.get_data_from_file(data_file_path)
drawer_pyvis.draw_graph(data["nodes"], data["edges"])
i = ''
while i != 'q':
i = input("Enter command:")
if i == 'n':
name = input("Name of new node:")
add_node(data, name)
elif i == 'e':
u = input("Name of first node:")
v = input("Name of second node:")
title = input("Title for the edge:")
edge = {"u": u, "v": v, "title": title}
add_edge(data, edge)
elif i == 'l':
drawer_pyvis.draw_graph(data["nodes"], data["edges"])
elif i == 's':
break
else:
print("Sorry, I didn't understand :( Try 'n' for new node, 'e' for new edge, or 's' for save & exit.")
file_helper.write_data_to_file(data_file_path, data)
print("Done! See you soon!")