更新bug
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
"""Read a listener log tolerantly and print either a time window or keyword hits.
|
||||
|
||||
Usage:
|
||||
python tmp/scan_log.py <log> --window HH:MM:SS HH:MM:SS
|
||||
python tmp/scan_log.py <log> --find "key1|key2"
|
||||
"""
|
||||
import re
|
||||
import sys
|
||||
|
||||
path = sys.argv[1]
|
||||
mode = sys.argv[2]
|
||||
with open(path, "rb") as fh:
|
||||
text = fh.read().decode("utf-8", errors="replace")
|
||||
lines = text.splitlines()
|
||||
|
||||
if mode == "--window":
|
||||
start, end = sys.argv[3], sys.argv[4]
|
||||
for line in lines:
|
||||
stamp = line[:8]
|
||||
if re.match(r"\d\d:\d\d:\d\d", stamp) and start <= stamp <= end:
|
||||
print(line)
|
||||
else:
|
||||
keys = sys.argv[3].split("|")
|
||||
for line in lines:
|
||||
if any(k in line for k in keys):
|
||||
print(line)
|
||||
Reference in New Issue
Block a user