File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import io
2+ from textfsm import TextFSM
3+
4+ textFSM_template = """Value Year (\d+)
5+ Value MonthDay (\d+)
6+ Value Month (\w+)
7+ Value Timezone (\S+)
8+ Value Time (..:..:..)
9+
10+ Start
11+ ^${Time}.* ${Timezone} \w+ ${Month} ${MonthDay} ${Year} -> Record"""
12+
13+ raw_data = "17:00:00.0 CET Mon Okt 26 2021"
14+
15+ template = io .StringIO (textFSM_template )
16+ parser = TextFSM (template )
17+ output = parser .ParseTextToDicts (text = raw_data )
18+
19+ print (output )
Original file line number Diff line number Diff line change 55from textfsm import TextFSM
66
77app = Flask (__name__ , static_url_path = "/static" )
8- app .config ['JSON_SORT_KEYS' ] = False
8+ app .config ["JSON_SORT_KEYS" ] = False
9+
10+
11+ config = {"name" : "TextFSM" , "data" : "RAW" , "rendered" : "JSON" }
912
1013
1114@app .route ("/" )
1215def index ():
13- return render_template ("index.html" )
16+ return render_template ("index.html" , ** config )
1417
1518
1619@app .route ("/examples" )
@@ -35,7 +38,7 @@ def rend():
3538 return resp
3639 textFSM_template = data .get ("template" , "" )
3740 raw_data = data .get ("data" )
38-
41+
3942 try :
4043 template = io .StringIO (textFSM_template )
4144 parser = TextFSM (template )
Original file line number Diff line number Diff line change 1010 < link rel ="stylesheet " href ="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css "
1111 integrity ="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk " crossorigin ="anonymous ">
1212
13- < title > TextFSM101 </ title >
13+ < title > {{name}}101 </ title >
1414 < link rel ="shortcut icon " href ="{{ url_for('static', filename='favicon.ico') }} ">
1515
1616 < style >
3131
3232< body >
3333 < div class ="jumbotron text-center ">
34- < h1 > TextFSM 101</ h1 >
35- < p > Playground for TextFSM templates</ p >
34+ < h1 > {{name}} 101</ h1 >
35+ < p > Playground for {{name}} templates</ p >
3636 </ div >
3737
3838 < div id ="alerts ">
@@ -136,20 +136,20 @@ <h1>TextFSM 101</h1>
136136 < div class ="row ">
137137 < div class ="col-lg-4 ">
138138 < div class ="form-group ">
139- < label for ="textData "> Data < small > RAW </ small > </ label >
139+ < label for ="textData "> Data < small > {{data}} </ small > </ label >
140140 < textarea class ="form-control show-spaces " id ="textData " name ="data " rows ="20 "> </ textarea >
141141 </ div >
142142 </ div >
143143 < div class ="col-lg-4 ">
144144 < div class ="form-group ">
145- < label for ="textTemplate "> Template < small > TextFSM </ small > </ label >
145+ < label for ="textTemplate "> Template < small > {{name}} </ small > </ label >
146146 < textarea class ="form-control show-spaces " id ="textTemplate " name ="template "
147147 rows ="20 "> </ textarea >
148148 </ div >
149149 </ div >
150150 < div class ="col-lg-4 ">
151151 < div class ="form-group ">
152- < label for ="textRendered " disabled > Rendered < small > JSON </ small > </ label >
152+ < label for ="textRendered " disabled > Rendered < small > {{rendered}} </ small > </ label >
153153 < textarea class ="form-control show-spaces " id ="textRendered " rows ="20 " disabled > </ textarea >
154154 </ div >
155155 </ div >
You can’t perform that action at this time.
0 commit comments