-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
50 lines (45 loc) · 1.74 KB
/
main.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
import aprslib
import logging
import requests
import json
import configparser
# Create a new configparser object
config = configparser.ConfigParser()
config.read('config.ini')
webhook = config['dcdgte']['WEBHOOK_URL']
def send_discord_message(webhook_url, sender, message):
payload = {
"username": sender,
"content": message
}
headers = {
"Content-Type": "application/json"
}
response = requests.post(webhook_url, data=json.dumps(payload), headers=headers)
if response.status_code != 204:
print("Failed to send Discord message:", response.text)
def callback(packet):
if "addresse" in packet:
if "DCDGTE" in packet['addresse']:
print(packet)
send_discord_message(webhook, "DCDGTE", f"{packet['from']}: {packet['message_text']}")
if "msgNo" in packet:
print("Creating temporary connection")
temp_AIS = aprslib.IS(config['dcdgte']['ACK_CALLSIGN'], host="rotate.aprs.net", port="14580", passwd=config['dcdgte']['ACK_PASSCODE'])
temp_AIS.connect(blocking=True)
print("Responding with ACK")
dest_portion = packet['from']
ack_packet = f"DCDGTE>DCDGTE::{dest_portion.ljust(9)}:ack{packet['msgNo']}"
print(ack_packet)
temp_AIS.sendall(ack_packet)
print("Closing temporary connection")
temp_AIS.close()
print("Setting login...")
AIS = aprslib.IS("N0CALL", host="rotate.aprs.net", port="14580", passwd="-1")
print("Logged in...")
AIS.set_filter("t/m")
print("Filter set...")
AIS.connect()
print("Connected...")
# by default `raw` is False, then each line is ran through aprslib.parse()
AIS.consumer(callback, raw=False)