Skip to content

Instantly share code, notes, and snippets.

@phearnot
Last active January 11, 2021 10:37
Show Gist options
  • Save phearnot/75460551e67b35cdcbfc9055006d93ca to your computer and use it in GitHub Desktop.
Save phearnot/75460551e67b35cdcbfc9055006d93ca to your computer and use it in GitHub Desktop.
from datetime import datetime
import fileinput, re
MESSAGE_REGEX = re.compile(r'(^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}) .+ - ((New height|Imported|Opening import).+)$')
first_ts = 0
def process(line):
global first_ts
result = MESSAGE_REGEX.match(line)
if result:
message_ts = int(datetime.fromisoformat(result[1].replace(',', '.')).timestamp() * 1000)
if first_ts == 0:
first_ts = message_ts
else:
offset = message_ts - first_ts
message = result[2].replace('New height: ', '')
print(f'{offset},{message}')
for line in fileinput.input():
process(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment