Skip to content

Instantly share code, notes, and snippets.

@kennu
Created March 27, 2020 16:46
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 kennu/52c55026f1c50f962ab7c86b80904524 to your computer and use it in GitHub Desktop.
Save kennu/52c55026f1c50f962ab7c86b80904524 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
import json
import re
def acars2json(filename):
messages = []
message = { 'header':'', 'content': ''}
with open(filename) as f:
line = f.readline()
while line:
m = re.match(r'^(\d+:\d+:\d+) (\d+-\d+-\d+) (.*)$', line.strip())
if m:
if message['header']:
messages.append(message)
message['header'] = {
'time': m.group(1),
'date': m.group(2),
'info': m.group(3),
}
message['content'] = ''
else:
content = re.sub(r'^\t+', '', line.strip())
if content:
message['content'] += content + '\n'
line = f.readline()
if message['header']:
messages.append(message)
print(json.dumps(messages, indent=2))
if __name__ == '__main__':
acars2json('acars-log-20-03-27.txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment