-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdirewrite.py
54 lines (44 loc) · 1.64 KB
/
direwrite.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pandas as pd
import time
from datetime import date
from papirus import PapirusTextPos
#CONFIG
refresh = 30 #refresh time
logdir = '/home/gktnc/direwolf-logs'
today = date.today()
logfile = f"{logdir}/{today}.log"
#initialize Papirus display
text = PapirusTextPos()
text.Clear()
text.AddText("Direwrite for APRS", 20, 20, Id="splash", size=20)
time.sleep(3)
text.RemoveText("splash")
text.AddText(f"Initializing...\nRefresh rate {refresh} secs.", 0, 0, Id="message", size=15)
#at refresh interval, read csv, update display, don't update if no change
try:
while True:
#read last line of log file, handle new lines in data
try:
df_curr = pd.read_csv(logfile, encoding = "ISO-8859-1").tail(1).replace(r'\n',' ', regex=True)
cols = df_curr[['isotime', 'source', 'heard', 'symbol', 'level', 'latitude', 'longitude', 'comment']]
row_list = cols.values.flatten().tolist()
isotime, source, heard, symbol, level, latitude, longitude, comment = row_list
#write to display
msg = (f"{isotime}\n"
f"{source}, {heard}, {symbol}, {level}\n"
f"{latitude}, {longitude}\n"
f"{comment}\n"
)
text.UpdateText("message", msg)
#show error if no logs yet
except:
text.UpdateText("message", "Waiting for logs to populate...")
#wait for refresh time
finally:
time.sleep(refresh)
except KeyboardInterrupt:
print("Keyboard interrupt: Closing Direwolf...")
text.Clear()
except Exception as e:
print("Exception encountered:", e)
text.Clear()