-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstep_5.py
51 lines (37 loc) · 821 Bytes
/
step_5.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
47
48
49
50
51
import textfsm
import json
from io import StringIO
### step 5 remove the clutter
# In this step we will have to remove the clutter.
# Learn about states they really powerfull tool
##
template = """
Value Firstname ([\w]+)
Value Lastname ([\w]+)
Start
^${Firstname}.${Lastname} -> Record
""".strip()
result = """
Firstname Lastname
------------------
John Doe
Jane Dye
other users
Jon Dotwo
Jan Dytwo
"""
def run(result):
t = textfsm.TextFSM(StringIO(template))
raw_list = t.ParseText(result.strip())
return [dict(zip(t.header, i)) for i in raw_list]
output = run(result)
print(json.dumps(output, indent=2))
template_with_answer = """
Value Firstname ([\w]+)
Value Lastname ([\w]+)
Start
^------------------ -> Name
Name
^other users
^${Firstname}.${Lastname} -> Record
""".strip()