-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaprx-rf2json.py
More file actions
executable file
·34 lines (26 loc) · 1.03 KB
/
aprx-rf2json.py
File metadata and controls
executable file
·34 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import aprslib
import re
import json
from datetime import datetime
p = re.compile(r'^(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\s+(?P<source>\S+)\s+(?P<direction>R|T)\s+(?P<raw>.+)$')
with open('aprx-rf.log', 'rt') as log:
for count,line in enumerate(log):
m = re.match(p, line.strip())
if not m:
continue
data = m.groupdict()
if data['source'] != 'HB9TF-1' and data['source'] != 'HB9TF-2':
continue
try:
aprs_data = aprslib.parse(data['raw'])
except:
continue
aprs_data['source_direction'] = data['direction']
aprs_data['source'] = data['source']
call_ssid = aprs_data['from'].split( '-', 1)
aprs_data['from_ssid'] = '1'
aprs_data['from_call'] = call_ssid[0]
if len(call_ssid) == 2:
aprs_data['from_ssid'] = call_ssid[1]
aprs_data['timestamp'] = datetime.strptime(data['timestamp'], '%Y-%m-%d %H:%M:%S.%f').timestamp()
print(json.dumps(aprs_data))