Okay, so I am new to the whole python world so bear with me.
Background: We are trying to offload logs into mongo to be able to query and search for them quicker. The device already prints them in a decent format EXCEPT in between each }{ to begin and end the data object something like this:
¾ïúÀï{"id":"xxx","timestamp":xxx,"payloadType":"xxx","payload":{"protocol":"xxx","zoneID":xxx,"zoneName":"xxx","eventType":"xxx"}}’ÂCº¾ïúÀï{"id":"xxx","timestamp":xxx,"payloadType":"xxx","payload":{"protocol":"xxx","zoneID":xxx,"zoneName":"xxx","eventType":"xx}}
Using the following I've been able to convert it to bytes then back to a string which outputs as:
f = open('logfile', 'r')
file_data = f.read()
f.close()data = file_data.encode('utf-8')print(str(data))>>>b'\xc2\xbe\xc3\xaf\xc3\xba\xc3\x80\x01\xc3\xaf{"id":"xxx","timestamp":xxx,"payloadType":"xxx","payload":{"protocol":"xxx","zoneID":xxx,"zoneName":"xxx","eventType":"xxx"}}
In my mind this is easier to deal with than the ugly characters seen above but I don't know.
This is just a sample..there are thousands upon thousands of lines returned in this log. In my mind, ideally the best way to go about this would be to remove all characters at the beginning of the string before { and all characters in between }}{