File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change 44Usage: ws_listener.py <location>
55"""
66import argparse
7+ import json
78
89from simple_websocket import Client , ConnectionClosed
910
@@ -22,7 +23,34 @@ def main(c_args: argparse.Namespace):
2223 try :
2324 while True :
2425 data = ws .receive ()
25- print (data )
26+ msg_type = "(unknown)"
27+ msg = "(unknown)"
28+ ordinal = "(unknown)"
29+ timestamp = "(unknown)"
30+ if data [0 ] == "{" :
31+ # A JSON message
32+ data_map = json .loads (data )
33+ msg_type = data_map ["message_type" ]
34+ msg = data_map ["message_body" ]
35+ ordinal = data_map ["ess_ordinal" ]
36+ timestamp = data_map ["ess_timestamp" ]
37+ else :
38+ # A protocol buffer message
39+ sections = data .split ("|" )
40+ print (data )
41+ msg_type = sections [0 ]
42+ msg = sections [1 ]
43+ if len (sections ) > 2 :
44+ ordinal = sections [2 ].split ()[1 ]
45+ timestamp = sections [3 ].split ()[1 ]
46+ else :
47+ ordinal = "(not present)"
48+ timestamp = "(not present)"
49+ print ("---------" )
50+ print (f" ORDINAL: { ordinal } " )
51+ print (f"TIMESTAMP: { timestamp } " )
52+ print (f" TYPE: { msg_type } " )
53+ print (f" BODY: { msg } " )
2654 except (KeyboardInterrupt , EOFError , ConnectionClosed ):
2755 ws .close ()
2856
You can’t perform that action at this time.
0 commit comments