Skip to content

Instantly share code, notes, and snippets.

@udoklein
Created May 17, 2018 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save udoklein/ee4995c6c87b93d4adbf6a7e1a17d0f0 to your computer and use it in GitHub Desktop.
Save udoklein/ee4995c6c87b93d4adbf6a7e1a17d0f0 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
"""Extract and analyze lines of the format
Decoded time: 18-05-14 1 19:36:05 CEST ..
from stdin or from file. Will search if the
decoded time has any unexpected jumps. Intended
for analyzing output of the "Swiss Army Debug Helper"
in mode "Da"
"""
import fileinput
import datetime
import re
# Decoded time: 1 8 - 0 5 - 1 4 1 1 9 : 3 6 : 0 5
regex = re.compile('^Decoded time: (\d\d)-(\d\d)-(\d\d) \d (\d\d):(\d\d):(\d\d)')
one_second = datetime.timedelta(seconds=1)
zero_seconds = datetime.timedelta(seconds=0)
previous_time = None
for line in fileinput.input():
match = regex.match(line)
if match:
year, month, day, hour, minute, second = (int(x) for x in match.group(1, 2, 3, 4, 5, 6))
year += 2000
parsed_time = datetime.datetime(year, month, day, hour, minute, second)
if previous_time:
delta = parsed_time - previous_time
if delta > one_second or delta < zero_seconds:
print "Discontinuity detected, " + str(previous_time) + " -> " + str(parsed_time)
print line
previous_time = parsed_time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment