-
Notifications
You must be signed in to change notification settings - Fork 0
/
adam_script.py
executable file
·46 lines (33 loc) · 1.17 KB
/
adam_script.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
#!/usr/local/bin/python
import unicodecsv as csv
import json
import sys
def load_dump(filename):
leaky = []
with open(filename) as f:
for line in f.readlines():
leaky.append(json.loads(line))
return leaky
def make_node_and_relationship_lists(objects):
nodes = [['address', 'type', 'size', 'name', 'value']]
relationships = [['start', 'end']]
for item in objects:
row = [
item['address'],
item['type'],
item['size'],
item.get('name', '').replace("\"", """).replace(",", ","),
unicode(item.get('value', '')).replace("\"", """).replace(",", ",")
]
nodes.append(row)
for child in item['refs']:
relationships.append([item['address'], child])
return nodes, relationships
def write_to_csv(list_of_lists, name):
with open(name, 'w') as f:
writer = csv.writer(f)
writer.writerows(list_of_lists)
objs = load_dump(sys.argv[1])
nodes, relationships = make_node_and_relationship_lists(objs)
write_to_csv(nodes, "nodes-{}".format(sys.argv[1]))
write_to_csv(relationships, "rels-{}".format(sys.argv[1]))