So i'm pretty new to using python but i have some data constantly being piped to a python script that reads the information from sys.stdin.readline() and then using re.search to filter for a specific bit of information. The problem is that it only reads the string of information that comes and then exits.
while True:
the_line = sys.stdin.readline()
m = re.search(',"data":"(.+?)}]}', the_line)
if m:
print (m.group(1))
A sample input (sorry i know it is messy)
stat update: {"stat":{"time":"2018-02-03 19:37:59 GMT","lati":6.81661,"long":- 58.11185,"alti":0,"rxnb":0,"rxok":0,"rxfw":0,"ackr":0.0,"dwnb":0,"txnb":0,"pfrm":"Single Channel Gateway","mail":"kevic.lall@yahoo.com","desc":"433 MHz gateway test project 1.0"}}
Packet RSSI: -56, RSSI: -97, SNR: 9, Length: 10
rxpk update: {"rxpk": [{"tmst":4153364745,"chan":0,"rfch":0,"freq":433.000000,"stat":1,"modu":"LORA" ,"datr":"SF7BW125","codr":"4/5","lsnr":9,"rssi":- 56,"size":10,"data":"aGVsbG8gMzA1Nw=="}]}
Packet RSSI: -49, RSSI: -96, SNR: 9, Length: 10
rxpk update: {"rxpk":[{"tmst":4155404009,"chan":0,"rfch":0,"freq":433.000000,"stat":1,"modu":"LORA","datr":"SF7BW125","codr":"4/5","lsnr":9,"rssi":-49,"size":10,"data":"aGVsbG8gMzA1OA=="}]}
Packet RSSI: -51, RSSI: -97, SNR: 9, Length: 10
....
these are just a couple lines of what is constantly streaming.
NOTE The input does not appear as is here but rather appears line by line as the program i am piping to the python script continues to run
thus, the output i want should be
aGVsbG8gMzA1Nw=="
aGVsbG8gMzA1OA=="
....
constantly streaming
but instead of that, i do not get anything printed, instead the program just hangs until i manually hit Ctrl+C
the 1st string just exits because it doesn't contain the required information and even if i did change it to filter something that is there, it prints the output i want then exist and stops the program being piped to the python script as well upon exit Is there a more efficient way to read and filter the information? can i still use the re.search function?
Also, the reason i am reading it line by line with sys.stdin.realine() is because i want to filter each line to send via MQTT
Edited for clarity