Created
November 15, 2017 02:20
-
-
Save thiamteck/f7a5cbdc4fd8577ea76b478e43a083ec to your computer and use it in GitHub Desktop.
A more readable view for capture file of Selenium SMPPSim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import fileinput | |
import shlex | |
## | |
# Usage: tail -f *.capture | python LogViewer.py | |
## | |
def construct_dictionary(line): | |
# ref: https://stackoverflow.com/a/38787616/90101 | |
lexer = shlex.shlex(line, posix=True) | |
lexer.whitespace_split = True | |
lexer.whitespace = ',' | |
props = {} | |
previous_key = "_na" # previous key-value's key | |
for pair in lexer: | |
token_list = pair.split("=", 1) | |
if (len(token_list) == 2): | |
props[token_list[0]] = token_list[1] | |
previous_key = token_list[0]; | |
elif (previous_key in props): | |
# to handle key value that contains seperator (,), i.e. short_message=Hello, from SMPPSim | |
props[previous_key] = props[previous_key] + "," + token_list[0] | |
return props | |
for line in fileinput.input(): | |
props = construct_dictionary(line); | |
if ('cmd_id' not in props): | |
continue | |
if (props['cmd_id'] == '4'): | |
print "%s : [MT] [%20s] -> [%20s] : %s" % (datetime.datetime.now(), props['source_addr'], props['dest_addr'], props['short_message'].rstrip()) | |
elif (props['cmd_id'] == '5'): | |
print "%s : [MO] [%20s] <- [%20s] : %s" % (datetime.datetime.now(), props['destination_addr'], props['source_addr'], props['short_message'].rstrip()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment