-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
aprsnotify.py
executable file
·727 lines (595 loc) · 24.5 KB
/
aprsnotify.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
#################################################################################
# APRSNotify
# Developed by: Jeff Lehman, N8ACL
# Current Version: 02032023
# https://github.com/n8acl/aprsnotify
# Questions? Comments? Suggestions? Contact me one of the following ways:
# E-mail: n8acl@qsl.net
# Discord: Ravendos#7364
# Mastodon: @n8acl@mastodon.radio
# Website: https://www.qsl.net/n8acl
################### DO NOT CHANGE BELOW #########################
# Import our Libraries
import time
import os
from os import system
import datetime
import sqlite3
import sys
import json
import http.client, urllib
from sqlite3 import Error
try:
import requests
except ImportError:
exit('This script requires the requests module\nInstall with: pip3 install requests')
try:
import telegram
except ImportError:
exit('This script requires the python-telegram-bot module\nInstall with: pip3 install python-telegram-bot')
try:
from geopy.geocoders import Nominatim
except ImportError:
exit('This script requires the geopy module\nInstall with: pip3 install geopy')
try:
from mastodon import Mastodon
except ImportError:
exit('This script requires the mastodon.py module\nInstall with: pip3 install mastodon.py')
try:
from discord_webhook import DiscordWebhook, DiscordEmbed
except ImportError:
exit('This script requires the discord_webhook module\nInstall with: pip3 install discord_webhook')
try:
from matterhook import Webhook
except ImportError:
exit('This script requires the matterhook module\nInstall with: pip3 install matterhook')
######################################################################################################################
# Define Variables and static objects
degree_sign= u'\N{DEGREE SIGN}'
fixed_station = 0
aprsfi_api_base_url = "https://api.aprs.fi/api/get"
owm_api_base_url = "http://api.openweathermap.org/data/2.5/weather"
geolocator = Nominatim(user_agent="aprsnotify")
db_file = os.path.dirname(os.path.abspath(__file__)) + "/aprsnotify.db"
linefeed = "\n"
pos_callsign_list = []
msg_callsign_list = []
wx_callsign_list = []
goodposdata = False
goodmsgdata = False
goodwxdata = False
debug = False
######################################################################################################################
# Define Functions
def create_connection(db_file):
# Creates connection to APRSNotify.db SQLlite3 Database
conn = None
try:
conn = sqlite3.connect(db_file)
except Error as e:
print(e)
return conn
def exec_sql(conn,sql):
# Executes SQL for Updates, inserts and deletes
cur = conn.cursor()
cur.execute(sql)
conn.commit()
def select_sql(conn,sql):
# Executes SQL for Selects
cur = conn.cursor()
cur.execute(sql)
return cur.fetchall()
def get_api_data(url):
# get JSON data from api's with just a URL
return requests.get(url=url).json()
def get_api_data_payload(url,payload):
# get JSON data from api's
try:
responses = requests.get(url=url,params=payload).json()
except ValueError as e:
return 0
return responses
def get_curr_wx(lat, lon):
# Return Conditions and Temp for the packet location.
if units_to_use == 1:
units = 'metric'
else:
units = 'imperial'
owm_payload = {
'lat': lat,
'lon': lon,
'units': units,
'appid': openweathermapkey
}
data = get_api_data_payload(owm_api_base_url,owm_payload)
return data['weather'][0]['main'], data['main']['temp'] # Conditions, temp
def get_location(lat,lng):
# Reverse geocode with openstreetmaps for location
osm_address = geolocator.reverse(lat.strip()+","+lng.strip())
return osm_address.address
def get_grid(dec_lat, dec_lon):
## Function developed by Walter Underwood, K6WRU https://ham.stackexchange.com/questions/221/how-can-one-convert-from-lat-long-to-grid-square
# Returns the Grid Square for the packet location
upper = 'ABCDEFGHIJKLMNOPQRSTUVWX'
lower = 'abcdefghijklmnopqrstuvwx'
if not (-180<=dec_lon<180):
sys.stderr.write('longitude must be -180<=lon<180, given %f\n'%dec_lon)
sys.exit(32)
if not (-90<=dec_lat<90):
sys.stderr.write('latitude must be -90<=lat<90, given %f\n'%dec_lat)
sys.exit(33) # can't handle north pole, sorry, [A-R]
adj_lat = dec_lat + 90.0
adj_lon = dec_lon + 180.0
grid_lat_sq = upper[int(adj_lat/10)]
grid_lon_sq = upper[int(adj_lon/20)]
grid_lat_field = str(int(adj_lat%10))
grid_lon_field = str(int((adj_lon/2)%10))
adj_lat_remainder = (adj_lat - int(adj_lat)) * 60
adj_lon_remainder = ((adj_lon) - int(adj_lon/2)*2) * 60
grid_lat_subsq = lower[int(adj_lat_remainder/2.5)]
grid_lon_subsq = lower[int(adj_lon_remainder/5)]
return grid_lon_sq + grid_lat_sq + grid_lon_field + grid_lat_field + grid_lon_subsq + grid_lat_subsq
def send_telegram(msg, msg_type, lat,lng, bot_token, chat_id):
# msg_types
# 1: Postion Data
# 2: Weather Data
# 3: APRS message
# Sends the message text to Telegram. This is used for both status and message sending
bot = telegram.Bot(token=bot_token)
if msg_type in [1,2]:
bot.sendMessage(chat_id=chat_id, text=msg)
else:
bot.sendMessage(chat_id=chat_id, text=msg)
if (include_map_image_telegram == 1 and msg_type not in [2,3]): # Includes a map of the packet location in Telegram
bot.sendLocation(chat_id=chat_id, latitude=lat, longitude=lng, disable_notification=True)
def send_mastodon(msg):
mastodon_api = Mastodon(mastodonkeys["client_id"], mastodonkeys["client_secret"], mastodonkeys["user_access_token"], api_base_url=mastodonkeys["api_base_url"])
mastodon_api.toot(micro_status)
def send_discord(msg,wh_url, msg_type, station):
# webhook = DiscordWebhook(url=wh_url, content=msg)
# response = webhook.execute()
if msg_type == 1:
title = station + " Position Report"
elif msg_type == 2:
title = station + " Weather Report"
elif msg_type == 3:
title = "Message Notification"
webhook = DiscordWebhook(url=wh_url)
embed = DiscordEmbed(title=title, description=msg)
webhook.add_embed(embed)
response = webhook.execute()
def send_mattermost(msg,wh_url, api_key):
mm_bot = Webhook(mattermostwh["wh_url"], mattermostwh["apikey"])
mm_bot.send(msg)
def send_pushover(msg):
connn = http.client.HTTPSConnection("api.pushover.net:443")
connn.request("POST", "/1/messages.json",
urllib.parse.urlencode({
"token": pushover["pushover_token"],
"user": pushover["pushover_userkey"],
"message": msg,
}), { "Content-type": "application/x-www-form-urlencoded" })
connn.getresponse()
def send_slack(msg,wh_url):
response = requests.post(
wh_url, data=json.dumps(msg),
headers={'Content-Type': 'application/json'}
)
######################################################################################################################
# Check for version arguement and return just the version
if len(sys.argv)>1:
if sys.argv[1] == 'version':
sql = "select version from config;"
conn = create_connection(db_file)
result = select_sql(conn, sql)
for row in result:
print("APRSNotify Release " + row[0])
sys.exit()
######################################################################################################################
######################################################################################################################
# Check for first run
if not os.path.exists(db_file):
print(linefeed + "******** Your Database for APRSNotify is not configured. Please run an_util.py ********" + linefeed)
sys.exit()
######################################################################################################################
# Load Data from Database into variables
# Create Database Connection
conn = create_connection(db_file)
# Build Position Callsign list
result = select_sql(conn, "select callsign from callsignlists where listtype = 'POS';")
for row in result:
pos_callsign_list.append(row[0])
# Build Message Callsign list
result = select_sql(conn, "select callsign from callsignlists where listtype = 'MSG';")
for row in result:
msg_callsign_list.append(row[0])
# Build Weather Station Callsign list
result = select_sql(conn, "select callsign from callsignlists where listtype = 'WX';")
for row in result:
wx_callsign_list.append(row[0])
# Get api keys from database
sql = """select
telegram_bot_token,
telegram_poswx_chat_id,
aprsfikey,
openweathermapkey,
mastodon_client_id,
mastodon_client_secret,
mastodon_api_base_url,
mastodon_user_access_token,
discord_poswx_wh_url,
mattermost_poswx_wh_url,
mattermost_poswx_api_key,
discord_aprsmsg_wh_url,
pushover_token,
pushover_userkey,
slack_poswx_wh_url,
slack_aprsmsg_wh_url,
mattermost_aprsmsg_wh_url,
mattermost_aprsmsg_api_key,
telegram_aprsmsg_chat_id,
telegram_club_chat_id,
telegram_club_bot_token,
discord_club_wh_url,
mattermost_club_wh_url,
mattermost_club_api_key,
slack_club_wh_url
from apikeys"""
result = select_sql(conn, sql)
for row in result:
telegramkeys = {
"my_bot_token": row[0],
"poswx_chat_id": row[1],
"aprsmsg_chat_id": row[18],
"club_bot_token": row[20],
"club_chat_id": row[19]
}
mastodonkeys = {
"client_id": row[4],
"client_secret": row[5],
"api_base_url": row[6],
"user_access_token": row[7]
}
discordwh = {
"poswx_wh_url": row[8],
"aprsmsg_wh_url": row[11],
"club_wh_url": row[21]
}
mattermostwh = {
"poswx_wh_url": row[9],
"poswx_apikey": row[10],
"msg_wh_url": row[16],
"msg_apikey": row[17],
"club_wh_url": row[22],
"club_apikey": row[23]
}
pushover = {
"pushover_token": row[12],
"pushover_userkey": row[13]
}
slackwh = {
"poswx_wh_url": row[14],
"aprsmsg_wh_url": row[15],
"club_wh_url": row[24]
}
aprsfikey = row[2]
openweathermapkey = row[3]
# Get config switches from database
sql = """select
telegram,
mastodon,
discord,
mattermost,
units_to_use,
include_map_image_telegram,
include_wx,
send_position_data,
send_weather_data,
aprsmsg_notify_telegram,
aprsmsg_notify_discord,
aprsmsg_notify_pushover,
aprsmsg_notify_mattermost,
aprsmsg_notify_slack,
slack,
club_telegram,
club_discord,
club_mattermost,
club_slack
from config"""
result = select_sql(conn, sql)
for row in result:
telegram = row[0]
mastodon = row[1]
discord = row[2]
mattermost = row[3]
units_to_use = row[4]
include_map_image_telegram = row[5]
include_wx = row[6]
send_position_data = row[7]
send_weather_data = row[8]
aprsmsg_notify_telegram = row[9]
aprsmsg_notify_discord = row[10]
aprsmsg_notify_pushover = row[11]
aprsmsg_notify_mattermost = row[12]
aprsmsg_notify_slack = row[13]
slack = row[14]
club_telegram = row[15]
club_discord = row[16]
club_mattermost = row[17]
club_slack = row[18]
# Get stamp data from database
sql = """select
lastpostime,
lastmsgid,
lastwxtime
from aprsstamps"""
result = select_sql(conn, sql)
for row in result:
lasttime = row[0]
lastmsgid = row[1]
lastwxtime = row[2]
######################################################################################################################
# Define static JSON Payloads for API retrevials
position_payload = {
'name': ",".join(pos_callsign_list),
'what': 'loc',
'apikey': aprsfikey,
'format': 'json'
}
msg_payload = {
'what': 'msg',
'dst': ",".join(msg_callsign_list),
'apikey': aprsfikey,
'format': 'json'
}
wx_payload = {
'name': ",".join(wx_callsign_list),
'what': 'wx',
'apikey': aprsfikey,
'format': 'json'
}
######################################################################################################################
# Main Program
###########################################
# Check for position data
if send_position_data:
data = get_api_data_payload(aprsfi_api_base_url,position_payload)
x=0
while x <= len(pos_callsign_list)-1 and x < data['found']:
if int(data['entries'][x]["lasttime"]) > lasttime:
station = data['entries'][x]["name"]
lat = str(data['entries'][x]["lat"])
lng = str(data['entries'][x]["lng"])
lasttime = data['entries'][x]["lasttime"]
if "speed" in data['entries'][x]:
speedkph = float(data['entries'][x]["speed"])
else:
fixed_station = True
goodposdata = True
break
else:
x=x+1
goodposdata = False
if goodposdata: # If we have a good set of packet data
#Create Status Message
status = station + ": "+ get_location(lat,lng)
if not fixed_station:
if units_to_use == 1:
status = status + " | Speed: "+ str(speedkph) + " kph"
else:
status = status + " | Speed: "+ str(round(speedkph/1.609344,1)) + " mph"
status = status + " | Grid: " + get_grid(float(lat),float(lng))
if include_wx:
#Get Weather Data
conditions, temp = get_curr_wx(lat, lng)
if units_to_use == 1:
status = status + " | WX: "+ str(temp) + degree_sign + " C & " + conditions
else:
status = status + " | WX: "+ str(temp) + degree_sign + " F & " + conditions
status = status + " | " + datetime.datetime.fromtimestamp(int(lasttime)).strftime('%H:%M:%S')
# Now finish off the status for Slack and everything else. The URL create method is different for Slack
slack_status = status + " | <https://aprs.fi/" + station + "|https://aprs.fi/" + station + ">"
status = status + " | https://aprs.fi/" + station
micro_status = status + " #APRS" # for microblogging sites like Twitter/Mastodon
msg_type = 1 # APRS Position Data
# Now we send the status
if not debug:
# msg_types
# 1: Postion Data
# 2: Weather Data
# 3: APRS message
# Send to a personal system
if telegram: # Send Status to Telegram
send_telegram(status, msg_type, lat,lng, telegramkeys["my_bot_token"], telegramkeys["poswx_chat_id"])
if mastodon: # Send Status to Mastodon
send_mastodon(micro_status)
if discord: # Send Status to Discord
send_discord(status, discordwh["poswx_wh_url"], msg_type, station)
if mattermost: # Send Status to Mattermost
send_mattermost(status, mattermostwh["poswx_wh_url"], mattermostwh["poswx_apikey"])
if slack: # Send Status to Slack
slack_msg = {'text': slack_status}
send_slack(slack_msg, slackwh["poswx_wh_url"])
# See about sending to a club system
if club_telegram: # Send Status to Telegram
send_telegram(status, 1, lat,lng, telegramkeys["club_bot_token"], telegramkeys["club_chat_id"])
if club_discord: # Send Status to Discord
send_discord(status, discordwh["club_wh_url"], msg_type, station)
if club_mattermost: # Send Status to Mattermost
send_mattermost(status, mattermostwh["club_wh_url"], mattermostwh["club_apikey"])
if club_slack: # Send Status to Slack
slack_msg = {'text': slack_status}
send_slack(slack_msg, slackwh["club_wh_url"])
else:
print(status) # Send to Screen (for debugging)
###########################################
# Now check for Weather Station Data
if send_weather_data:
data = get_api_data_payload(aprsfi_api_base_url,wx_payload)
x=0
while x <= len(wx_callsign_list)-1 and x < data['found']:
if int(data['entries'][x]["time"]) > lastwxtime:
station = data['entries'][x]["name"]
lastwxtime = data['entries'][x]["time"]
if "temp" in data['entries'][x]:
tempC = float(data['entries'][x]["temp"])
else:
tempC = 'None'
if "pressure" in data['entries'][x]:
pressure = float(data['entries'][x]["pressure"])
else:
pressure = 'None'
if "humidity" in data['entries'][x]:
humidity = float(data['entries'][x]["humidity"])
else:
humidity = 'None'
if "wind_direction" in data['entries'][x]:
wind_direction = float(data['entries'][x]["wind_direction"])
else:
wind_direction = 'None'
if "wind_speed" in data['entries'][x]:
wind_speed = float(data['entries'][x]["wind_speed"])
else:
wind_speed = 'None'
if "wind_gust" in data['entries'][x]:
wind_gust = float(data['entries'][x]["wind_gust"])
else:
wind_gust = 'None'
if "rain_1h" in data['entries'][x]:
rain_1h = float(data['entries'][x]["rain_1h"])
else:
rain_1h = 'None'
if "rain_24h" in data['entries'][x]:
rain_24h = float(data['entries'][x]["rain_24h"])
else:
rain_24h = 'None'
if "rain_mn" in data['entries'][x]:
rain_mn = float(data['entries'][x]["rain_mn"])
else:
rain_mn = 'None'
if "luminosity" in data['entries'][x]:
luminosity = float(data['entries'][x]["luminosity"])
else:
luminosity = 'None'
goodwxdata = True
break
else:
x=x+1
goodwxdata = False
if goodwxdata: # If we have a good set of packet data
#Create Status Message
status = station + " WX Data as of " + datetime.datetime.fromtimestamp(int(lastwxtime)).strftime('%H:%M:%S') + linefeed
if isinstance(tempC,float):
if units_to_use == 1:
status = status + "Temp: " + str(tempC) + degree_sign + " C" + linefeed
else:
status = status + "Temp: " + str(9.0/5.0 * tempC + 32) + degree_sign + " F" + linefeed
if isinstance(pressure,float):
status = status + "Pressure: " + str(pressure) + " mbar" + linefeed
if isinstance(humidity,float):
status = status + "Humidity: " + str(humidity) + "%" + linefeed
if isinstance(wind_direction,float):
status = status + "Wind Direction: " + str(wind_direction) + degree_sign + linefeed
if isinstance(wind_speed,float):
if units_to_use == 1:
status = status + "Wind Speed: " + str(round(wind_speed * 3.6,1)) + " kph" + linefeed
else:
status = status + "Wind Speed: " + str(round(wind_speed * 2.2369,1)) + " mph" + linefeed
if isinstance(wind_gust,float):
if units_to_use == 1:
status = status + "Wind Gust: " + str(round(wind_gust * 3.6,1)) + " kph" + linefeed
else:
status = status + "Wind Gust: " + str(round(wind_gust * 2.2369,1)) + " mph" + linefeed
if isinstance(rain_1h,float):
if units_to_use == 1:
status = status + "Rain 1Hr: " + str(round(rain_1h,1)) + " mm" + linefeed
else:
status = status + "Rain 1Hr: " + str(round(rain_1h * 0.03937007874,1)) + " in" + linefeed
if isinstance(rain_24h,float):
if units_to_use == 1:
status = status + "Rain 24Hr: " + str(round(rain_24h,1)) + " mm" + linefeed
else:
status = status + "Rain 24Hr: " + str(round(rain_24h * 0.03937007874,1)) + " in" + linefeed
if isinstance(rain_24h,float):
if units_to_use == 1:
status = status + "Rain Since Midnight: " + str(round(rain_mn,1)) + " mm" + linefeed
else:
status = status + "Rain Since Midnight: " + str(round(rain_mn * 0.03937007874,1)) + " in" + linefeed
if isinstance(luminosity,float):
status = status + "Luminosity: " + str(luminosity) + "W/m^2" + linefeed
# Now finish off the status for Slack and everything else. The URL create method is different for Slack
slack_status = status + " | <https://aprs.fi/" + station + "|https://aprs.fi/" + station + ">"
status = status + " | https://aprs.fi/" + station
msg_type = 2 # APRS Weather Data
if not debug:
# msg_types
# 1: Postion Data
# 2: Weather Data
# 3: APRS message
# Send to a personal system
if telegram: # Send Status to Telegram
send_telegram(status, msg_type, lat,lng, telegramkeys["my_bot_token"], telegramkeys["poswx_chat_id"])
if mastodon: # Send Status to Mastodon
send_mastodon(status)
if discord: # Send Status to Discord
send_discord(status, discordwh["poswx_wh_url"], msg_type, station)
if mattermost: # Send Status to Mattermost
send_mattermost(status, mattermostwh["poswx_wh_url"], mattermostwh["poswx_apikey"])
if slack: # Send Status to Slack
slack_msg = {'text': slack_status}
send_slack(slack_msg, slackwh["poswx_wh_url"])
# See about sending to a club system
if club_telegram: # Send Status to Telegram
send_telegram(status, msg_type, lat,lng, telegramkeys["club_bot_token"], telegramkeys["club_chat_id"])
if club_discord: # Send Status to Discord
send_discord(status, discordwh["club_wh_url"], msg_type, station)
if club_mattermost: # Send Status to Mattermost
send_mattermost(status, mattermostwh["club_wh_url"], mattermostwh["club_apikey"])
if club_slack: # Send Status to Slack
slack_msg = {'text': slack_status}
send_slack(slack_msg, slackwh["club_wh_url"])
else:
print(status) # Send to Screen (for debugging)
###########################################
# Now Check for messages to my callsign(s)
if aprsmsg_notify_telegram or aprsmsg_notify_discord or aprsmsg_notify_mattermost or aprsmsg_notify_slack or aprsmsg_notify_pushover:
data = get_api_data_payload(aprsfi_api_base_url,msg_payload)
x=0
while x <= len(msg_callsign_list)-1 and x < data['found']:
if int(data['entries'][x]["messageid"]) > lastmsgid:
srccall = data['entries'][x]["srccall"]
dstcall = data['entries'][x]["dst"]
msg = data['entries'][x]["message"]
dtstamp = data['entries'][x]["time"]
lastmsgid = data['entries'][x]["messageid"]
goodmsgdata = True
break
else:
x=x+1
goodmsgdata = False
if goodmsgdata: # If we have good msg data
msg_timestamp = datetime.datetime.fromtimestamp(int(dtstamp)).strftime('%H:%M:%S')
msg_datestamp = datetime.datetime.fromtimestamp(int(dtstamp)).strftime('%m/%d/%Y')
# create msg status and send to Telegram
msg_status = "On " + msg_datestamp + " at " + msg_timestamp + ", " + srccall + " sent " + dstcall + " the following APRS message: " + msg
msg_type = 3 # APRS Message Notification
if not debug:
if aprsmsg_notify_telegram:
send_telegram(msg_status, msg_type, lat,lng, telegramkeys["my_bot_token"], telegramkeys["msg_chat_id"])
if aprsmsg_notify_discord:
send_discord(msg_status,discordwh["aprsmsg_wh_url"], msg_type,'')
if aprsmsg_notify_pushover:
send_pushover(msg_status)
if aprsmsg_notify_slack:
slack_msg = {'text': msg_status}
send_slack(slack_msg,slackwh["aprsmsg_wh_url"])
if aprsmsg_notify_mattermost:
send_mattermost(msg, mattermostwh["msg_wh_url"], mattermostwh["msg_apikey"])
else:
print(msg_status) # Send to Screen (for debugging)
# Update aprsstamps table in database with lastmsgid/DT Stamp and close
sql = "update aprsstamps set lastpostime = " + str(lasttime) + ", lastmsgid = " + str(lastmsgid) + ", lastwxtime = " + str(lastwxtime) + ";"
if not debug:
exec_sql(conn, sql)
else:
print(sql)