From 3687cf23cc917f8042dd46928213dced1ce315c1 Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 5 Aug 2023 14:07:01 -0700 Subject: [PATCH] Added Comment Support & Better Lat/Long Detection --- sat2aprs.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/sat2aprs.py b/sat2aprs.py index e57b39f..b03703f 100644 --- a/sat2aprs.py +++ b/sat2aprs.py @@ -47,17 +47,25 @@ def webhook(): incoming_sms = request.form.get('Body', '') latitude = None longitude = None + comment = "" # Log incoming message print('Received Message:', incoming_sms) - # Search for latitude and longitude in the message using regular expressions - lat_long_match = re.search(r'Location:\s*(-?\d+\.\d+),(-?\d+\.\d+)', incoming_sms) + # Search for latitude, longitude, and comment in the message using regular expressions + lat_long_comment_match = re.search(r'(-?\d+\.\d+),(-?\d+\.\d+)\s*([^.\"\n]+)', incoming_sms) + + if lat_long_comment_match: + latitude = float(lat_long_comment_match.group(1)) + longitude = float(lat_long_comment_match.group(2)) + comment = lat_long_comment_match.group(3).strip() + + # If the comment is "undefined", use the default comment 'text' + if comment.lower() == "undefined": + comment = text - if lat_long_match: - latitude = float(lat_long_match.group(1)) - longitude = float(lat_long_match.group(2)) print('Detected Lat Long: ({}, {})'.format(latitude, longitude)) + print('Detected Comment:', comment) # Convert latitude and longitude to DDMM.MM format without dashes lat_ddmm = decimal_to_ddmm(latitude) @@ -65,15 +73,17 @@ def webhook(): print('Converted Lat Long to DDMM.MM: {}, {}'.format(lat_ddmm, long_ddmm)) print('{}/{}'.format(lat_ddmm, long_ddmm)) + print('APRS Comment:', comment) # Send APRS packet - send_aprs_packet(aprsUser, latitude, longitude, text) + send_aprs_packet(aprsUser, latitude, longitude, comment) else: - print('No Lat Long detected.') + print('No Lat Long and Comment detected.') response = MessagingResponse() return str(response) + if __name__ == '__main__': app.run(host='0.0.0.0', port=5001, debug=True)