From e88d545955666cc8e3a267878310dfb6e3ed09da Mon Sep 17 00:00:00 2001 From: KF7EEL Date: Wed, 25 Nov 2020 15:53:42 -0800 Subject: [PATCH] add hooks in code for shell commands --- gps_data.py | 13 ++++++++++++- gps_functions.py | 9 +++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 gps_functions.py diff --git a/gps_data.py b/gps_data.py index 09b67f6..63da7a5 100644 --- a/gps_data.py +++ b/gps_data.py @@ -61,6 +61,10 @@ import codecs #Needed for working with NMEA import pynmea2 +# Modules for executing commands/scripts +import os +from gps_functions import cmd_list + # Does anybody read this stuff? There's a PEP somewhere that says I should do this. __author__ = 'Cortney T. Buffington, N0MJS; Eric Craw, KF7EEL' __copyright__ = 'Copyright (c) 2020 Cortney T. Buffington' @@ -122,7 +126,14 @@ def process_sms(from_id, sms): if sms == 'ID': logger.info(str(get_alias(int_id(from_id), subscriber_ids)) + ' - ' + str(int_id(from_id))) if sms == 'TEST': - logger.info('This is a really cool function.') + logger.info('It works!') + try: + if sms in cmd_list: + logger.info('Executing command/script.') + os.popen(cmd_list[sms]).read() + except: + logger.info('Exception. Command possibly not in list, or other error.') + else: pass diff --git a/gps_functions.py b/gps_functions.py new file mode 100644 index 0000000..1166e1f --- /dev/null +++ b/gps_functions.py @@ -0,0 +1,9 @@ +# Various configurable options used in the GPS/Data application. + +# SMS message that triggers command +cmd_list = { + + 'LS' : 'ls -lsh', + 'UPTIME' : 'uptime' + + }