From a8c19f842632d18f2393c05784b1422453788ae6 Mon Sep 17 00:00:00 2001 From: Mason10198 <31994327+Mason10198@users.noreply.github.com> Date: Sat, 6 Apr 2024 11:48:09 -0500 Subject: [PATCH] Version update --- SkyControl.py | 12 ++++++++--- SkyDescribe.py | 2 +- SkywarnPlus.py | 54 ++++++++++++++++++++++++++++++++++++++------------ config.yaml | 16 ++++++++++++++- 4 files changed, 66 insertions(+), 18 deletions(-) diff --git a/SkyControl.py b/SkyControl.py index b236389..7a11148 100644 --- a/SkyControl.py +++ b/SkyControl.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 """ -SkyControl.py v0.6.2 by Mason Nelson +SkyControl.py v0.7.0 by Mason Nelson ================================== A Control Script for SkywarnPlus @@ -115,7 +115,9 @@ def silent_tailmessage(): Generates a 100ms silent audio file and replaces the existing tailmessage file, ensuring the audio is compatible with Asterisk (8000Hz, mono). """ - tailmessage_path = config["Tailmessage"].get("TailmessagePath", "/tmp/SkywarnPlus/wx-tail.wav") + tailmessage_path = config["Tailmessage"].get( + "TailmessagePath", "/tmp/SkywarnPlus/wx-tail.wav" + ) silence = AudioSegment.silent(duration=100) converted_silence = silence.set_frame_rate(8000).set_channels(1) converted_silence.export(tailmessage_path, format="wav") @@ -243,7 +245,11 @@ else: value = not current_value # Special handling for disabling SKYWARNPLUS or Tailmessage - if key in ["enable", "tailmessage"] and value is False and tailmessage_previously_enabled: + if ( + key in ["enable", "tailmessage"] + and value is False + and tailmessage_previously_enabled + ): silent_tailmessage() # Update the key in the config diff --git a/SkyDescribe.py b/SkyDescribe.py index 96721f8..644e205 100644 --- a/SkyDescribe.py +++ b/SkyDescribe.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 """ -SkyDescribe.py v0.6.2 by Mason Nelson +SkyDescribe.py v0.7.0 by Mason Nelson ================================================== Text to Speech conversion for Weather Descriptions diff --git a/SkywarnPlus.py b/SkywarnPlus.py index deb059b..a0f1083 100644 --- a/SkywarnPlus.py +++ b/SkywarnPlus.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 """ -SkywarnPlus.py v0.6.2 by Mason Nelson +SkywarnPlus.py v0.7.0 by Mason Nelson =============================================================================== SkywarnPlus is a utility that retrieves severe weather alerts from the National Weather Service and integrates these alerts with an Asterisk/app_rpt based @@ -1133,8 +1133,12 @@ def alert_script(alerts): previous_active_count = len(state.get("active_alerts", [])) LOGGER.debug("Previous active alerts count: %s", previous_active_count) - processed_alerts = set(state["alertscript_alerts"]) # Convert to a set for easier processing - active_alerts = set(state.get("active_alerts", [])) # Load active alerts from state, also as a set + processed_alerts = set( + state["alertscript_alerts"] + ) # Convert to a set for easier processing + active_alerts = set( + state.get("active_alerts", []) + ) # Load active alerts from state, also as a set LOGGER.debug("Processed alerts from state: %s", processed_alerts) LOGGER.debug("Active alerts from state: %s", active_alerts) @@ -1151,7 +1155,9 @@ def alert_script(alerts): LOGGER.debug("Cleared alerts: %s", cleared_alerts) # Update the active alerts in the state - state["active_alerts"] = list(alert_names) # Convert back to list for JSON serialization + state["active_alerts"] = list( + alert_names + ) # Convert back to list for JSON serialization LOGGER.debug("Updated active alerts in state: %s", state["active_alerts"]) # Fetch AlertScript configuration from global_config @@ -1203,7 +1209,9 @@ def alert_script(alerts): # Process each mapping for new alerts and issue a warning for wildcard clear commands for mapping in mappings: if "*" in mapping.get("Triggers", []) and mapping.get("ClearCommands"): - LOGGER.warning("Using ClearCommands with wildcard-based mappings ('*') might not behave as expected for all alert clearances.") + LOGGER.warning( + "Using ClearCommands with wildcard-based mappings ('*') might not behave as expected for all alert clearances." + ) LOGGER.debug("Processing mapping: %s", mapping) triggers = mapping.get("Triggers", []) @@ -1211,25 +1219,35 @@ def alert_script(alerts): nodes = mapping.get("Nodes", []) match_type = mapping.get("Match", "ANY").upper() - matched_alerts = [alert for alert in new_alerts if any(fnmatch.fnmatch(alert, trigger) for trigger in triggers)] + matched_alerts = [ + alert + for alert in new_alerts + if any(fnmatch.fnmatch(alert, trigger) for trigger in triggers) + ] LOGGER.debug("Matched alerts for mapping: %s", matched_alerts) # Check if new alerts matched the triggers as per the match type - if (match_type == "ANY" and matched_alerts) or (match_type == "ALL" and len(matched_alerts) == len(triggers)): + if (match_type == "ANY" and matched_alerts) or ( + match_type == "ALL" and len(matched_alerts) == len(triggers) + ): for alert in matched_alerts: processed_alerts.add(alert) LOGGER.debug("Processing alert: %s", alert) if mapping.get("Type") == "BASH": for cmd in commands: - cmd = cmd.format(alert_title=alert) # Replace placeholder with alert title + cmd = cmd.format( + alert_title=alert + ) # Replace placeholder with alert title LOGGER.info("AlertScript: Executing BASH command: %s", cmd) subprocess.run(cmd, shell=True) elif mapping.get("Type") == "DTMF": for node in nodes: for cmd in commands: dtmf_cmd = 'asterisk -rx "rpt fun {} {}"'.format(node, cmd) - LOGGER.info("AlertScript: Executing DTMF command: %s", dtmf_cmd) + LOGGER.info( + "AlertScript: Executing DTMF command: %s", dtmf_cmd + ) subprocess.run(dtmf_cmd, shell=True) # Process each mapping for cleared alerts @@ -1239,11 +1257,17 @@ def alert_script(alerts): triggers = mapping.get("Triggers", []) match_type = mapping.get("Match", "ANY").upper() - matched_cleared_alerts = [alert for alert in cleared_alerts if any(fnmatch.fnmatch(alert, trigger) for trigger in triggers)] + matched_cleared_alerts = [ + alert + for alert in cleared_alerts + if any(fnmatch.fnmatch(alert, trigger) for trigger in triggers) + ] LOGGER.debug("Matched cleared alerts for mapping: %s", matched_cleared_alerts) # Check if cleared alerts matched the triggers as per the match type - if (match_type == "ANY" and matched_cleared_alerts) or (match_type == "ALL" and len(matched_cleared_alerts) == len(triggers)): + if (match_type == "ANY" and matched_cleared_alerts) or ( + match_type == "ALL" and len(matched_cleared_alerts) == len(triggers) + ): for cmd in clear_commands: LOGGER.debug("Executing clear command: %s", cmd) if mapping.get("Type") == "BASH": @@ -1252,11 +1276,15 @@ def alert_script(alerts): elif mapping.get("Type") == "DTMF": for node in mapping.get("Nodes", []): dtmf_cmd = 'asterisk -rx "rpt fun {} {}"'.format(node, cmd) - LOGGER.info("AlertScript: Executing DTMF ClearCommand: %s", dtmf_cmd) + LOGGER.info( + "AlertScript: Executing DTMF ClearCommand: %s", dtmf_cmd + ) subprocess.run(dtmf_cmd, shell=True) # Update the state with the alerts processed in this run - state["alertscript_alerts"] = list(processed_alerts) # Convert back to list for JSON serialization + state["alertscript_alerts"] = list( + processed_alerts + ) # Convert back to list for JSON serialization LOGGER.debug("Saving state with processed alerts: %s", state["alertscript_alerts"]) save_state(state) LOGGER.debug("Alert script execution completed.") diff --git a/config.yaml b/config.yaml index fd540e3..4219228 100644 --- a/config.yaml +++ b/config.yaml @@ -1,4 +1,4 @@ -# SkywarnPlus v0.6.2 Configuration File +# SkywarnPlus v0.7.0 Configuration File # Author: Mason Nelson (N5LSN/WRKF394) # Please edit this file according to your specific requirements. @@ -310,6 +310,20 @@ AlertScript: # Completely enable/disable AlertScript Enable: false + # These are BASH or DTMF commands that are executed ONLY when the number of active alerts changes from ZERO to NON-ZERO. + # Use the same format as other AlertScript mappings (see below). + ActiveCommands: + - Type: BASH + Commands: + - 'echo "THE NUMBER OF ACTIVE ALERTS JUST CHANGED FROM ZERO TO NON-ZERO"' + + # These are BASH or DTMF commands that are executed ONLY when the number of active alerts changes from NON-ZERO to ZERO. + # Use the same format as other AlertScript mappings (see below). + InactiveCommands: + - Type: BASH + Commands: + - 'echo "THE NUMBER OF ACTIVE ALERTS JUST CHANGED FROM NON-ZERO TO ZERO"' + Mappings: # Define the mapping of alerts to either DTMF commands or bash scripts here. #