forked from secure-77/Perlite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pythonParser.py
41 lines (28 loc) · 966 Bytes
/
pythonParser.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
import json
f = open("perlite\Demo\metadata.json", "r")
filecontent = f.read()
metaJson = json.loads(filecontent)
notes = []
edges = []
for id, mdFiles in enumerate(metaJson):
notes.append(id)
notes[id] = {'id' : id , 'label' : mdFiles["fileName"]}
print(notes)
targetId = -1
srcId = -1
for mdFiles in metaJson:
if "links" in mdFiles:
for linkNames in mdFiles["links"]:
source = mdFiles["fileName"]
target = linkNames["link"]
for element in notes:
elementLabel = element.get('label')
if(elementLabel == target):
targetId = element.get('id')
if(elementLabel == source):
srcId = element.get('id')
if(targetId != -1 and srcId != -1):
edges.append({'from' : srcId , 'to' : targetId})
targetId = -1
srcId = -1
print(edges)