import sys import re import json from datetime import datetime err_re = re.compile("(?P.*?):(?P[0-9]+):(?P[0-9]+): (?P.*?): (?P.*)\n") stats = []; for line in sys.stdin: found = err_re.fullmatch(line) print(line, end="") if found: stats.append(found.groupdict()) print("FOUND", found.groupdict()) with open("stats.json", "a+") as out: out.write(json.dumps({"date": datetime.now().isoformat(), "messages": stats})); out.write("\n")