I am trying to get some values from txt file where lines has specific string. My text file contains more data like below,
2018-11-11 00:00:10 INFO ProtocolProcessor:417 - PUBLISH on server 80 from clientID <ClientId> on topic </data/AClientData> with QoS MOST_ONE
2018-11-11 00:00:10 INFO ProtocolProcessor:530 - Received Msg:{
"id" : "A001",
"val" : 62.0,
"ts" : "2018-11-10 23:41:21"
}
2018-11-11 00:00:10 INFO ProtocolProcessor:587 - send publish message to <tcp://35.166.43.154:80> on topic </data/BClientData>
2018-11-11 00:00:11 INFO Consumer:39 - Received a message of type PUBLISH
2018-11-11 00:00:11 INFO Consumer:58 - String received before queue:{
"id" : "B001",
"val" : 89.0,
"ts" : "2018-11-10 23:42:21"
}
From above text I want to print Received Msg: as below format where line contains /data/AClientData
id =A001,
value = 62.0
date = 2018-11-10 23:41:21
Code Tried :
searchString = '/data/AClientData'
search = open("C:\\ReadLogUsingPython.txt","r")
for line in search.readlines():
if searchString in line:
#here need to take value of next line Received Msg:{ }
#print each value
valueDict ={"id" : "A001","val" : 62.0,"ts" : "2018-11-10 23:41:21"}
print(valueDict['id'])
print(valueDict['val'])
print(valueDict['ts'])