Created
February 4, 2022 11:17
-
-
Save limebell/1f5bf6a22bc92a965ea087fdce3f0b82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
import re | |
import sys | |
file = open(sys.argv[1], 'r') | |
lines = file.readlines() | |
file.close() | |
dateformat = "%H:%M:%S" | |
prevtime = None | |
limit = 5 | |
count = 0 | |
print("parsing file with {:d} lines".format(len(lines))) | |
for i in range(0, len(lines)): | |
time = re.search('[0-9][0-9]:[0-9][0-9]:[0-9][0-9]', lines[i]) | |
if time is None: | |
continue | |
time = time.group() | |
time = datetime.strptime(time, dateformat) | |
if prevtime is None: | |
prevtime = time | |
continue | |
delta = time - prevtime | |
if delta > timedelta(seconds=limit): | |
print("Line #{:d} is logged after {:d} second: {:.0f}; ".format(i, limit, delta.total_seconds()) + lines[i].rstrip()) | |
count += 1 | |
prevtime = time | |
print("Total lines: {:d}".format(count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment