-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (33 loc) · 1.07 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
from itertools import islice
import graphviz
def main(filepath):
records = parse(filepath)
dot = graphviz.Digraph(graph_attr={'rankdir': 'LR'})
dot.format = 'svg'
for record in islice(records, 0, len(records)):
if record['name'] == '.':
continue
if record['type'] == 'NS':
dot.node(record['name'], record['name'])
dot.node(record['value'], record['value'])
dot.edge(record['name'], record['value'])
if record['type'] == 'A':
dot.node(record['value'], record['value'])
dot.edge(record['name'], record['value'])
dot.render('zones', view=False)
def parse(filepath):
records = []
with open(filepath, 'r') as f:
while True:
row = f.readline()
if row == '':
break
line = row.split(';')
record = {
'name': line[0],
'type': line[1],
'value': line[2].strip('\n'),
}
records.append(record)
return records
main('zone.csv')