From 2d45fef53c00ab9abe8511e435c1440f17b40b2f Mon Sep 17 00:00:00 2001 From: Mason10198 <31994327+Mason10198@users.noreply.github.com> Date: Fri, 4 Aug 2023 10:40:33 -0500 Subject: [PATCH] v0.4.3 update --- SkyControl.py | 2 +- SkyDescribe.py | 17 ++++++++++++----- SkywarnPlus.py | 46 +++++++++++++++++++++++++++++++++++++++------- UpdateSWP.py | 2 +- config.yaml | 2 +- 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/SkyControl.py b/SkyControl.py index a5bdc5f..dd5d644 100644 --- a/SkyControl.py +++ b/SkyControl.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 """ -SkyControl v0.4.2 by Mason Nelson +SkyControl v0.4.3 by Mason Nelson ================================== A Control Script for SkywarnPlus diff --git a/SkyDescribe.py b/SkyDescribe.py index 5c12684..49c5442 100644 --- a/SkyDescribe.py +++ b/SkyDescribe.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 """ -SkyDescribe v0.4.2 by Mason Nelson +SkyDescribe v0.4.3 by Mason Nelson ================================================== Text to Speech conversion for Weather Descriptions @@ -267,6 +267,13 @@ def convert_to_audio(api_key, text): return audio_file_path +def pluralize(word): + if word.endswith('s') or word.endswith('sh') or word.endswith('ch') or word.endswith('x'): + return word + 'es' + else: + return word + 's' + + def main(index_or_title): state = load_state() alerts = list(state["last_alerts"].items()) @@ -296,9 +303,9 @@ def main(index_or_title): if unique_instances == 1: description = alert_data[0]["description"] else: - description = "There are {} unique instances of {}. Describing the first one. {}".format( + description = "There are {} unique {} in the area. Describing the first one. {}".format( unique_instances, - alert, + pluralize(alert), alert_data[0]["description"] ) @@ -319,9 +326,9 @@ def main(index_or_title): if unique_instances == 1: description = alert_data[0]["description"] else: - description = "There are {} unique instances of {}. Describing the first one. {}".format( + description = "There are {} unique {} in the area. Describing the first one. {}".format( unique_instances, - alert, + pluralize(alert), alert_data[0]["description"] ) break diff --git a/SkywarnPlus.py b/SkywarnPlus.py index c420603..539dd44 100644 --- a/SkywarnPlus.py +++ b/SkywarnPlus.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 """ -SkywarnPlus v0.4.2 by Mason Nelson +SkywarnPlus v0.4.3 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 @@ -1345,6 +1345,34 @@ def supermon_back_compat(alerts): file.write("
".join(alert_titles)) +def detect_new_counties(old_alerts, new_alerts): + """ + Detect if any new counties have been added to an alert. + """ + is_new_counties = False + alerts_with_new_counties = {} + + for alert_name, alert_info in new_alerts.items(): + old_alert_info = old_alerts.get(alert_name, []) + old_county_codes = {info['county_code'] for info in old_alert_info} + new_county_codes = {info['county_code'] for info in alert_info} + added_counties = new_county_codes - old_county_codes + old_county_codes = {code.replace("{", "").replace("}", "").replace('"', "") for code in old_county_codes} + added_counties = {code.replace("{", "").replace("}", "").replace('"', "") for code in added_counties} + + if added_counties: + alerts_with_new_counties[alert_name] = new_alerts[alert_name] + LOGGER.info('{} for {} is now also affecting: {}'.format(alert_name, ", ".join(old_county_codes), ", ".join(added_counties))) + is_new_counties = True + + if COUNTY_WAVS and alerts_with_new_counties: + say_alerts(alerts_with_new_counties) + if config.get("Tailmessage", {}).get("TailmessageCounties", False): + build_tailmessage(alerts_with_new_counties) + + return is_new_counties + + def main(): """ The main function that orchestrates the entire process of fetching and @@ -1457,13 +1485,17 @@ def main(): LOGGER.debug("Sending pushover notification: %s", pushover_message) send_pushover(pushover_message, title="Alerts Changed") else: - if sys.stdin.isatty(): - # list of current alerts, unless there arent any, then current_alerts = "None" - current_alerts = "None" if len(alerts) == 0 else ", ".join(alerts.keys()) - LOGGER.info("No change in alerts.") - LOGGER.info("Current alerts: %s.", current_alerts) + if not detect_new_counties(last_alerts, alerts): + if sys.stdin.isatty(): + # list of current alerts, unless there arent any, then current_alerts = "None" + current_alerts = "None" if len(alerts) == 0 else ", ".join(alerts.keys()) + LOGGER.info("No change in alerts.") + LOGGER.info("Current alerts: %s.", current_alerts) + else: + LOGGER.debug("No change in alerts.") else: - LOGGER.debug("No change in alerts.") + state["last_alerts"] = alerts + save_state(state) if __name__ == "__main__": diff --git a/UpdateSWP.py b/UpdateSWP.py index ca2db2a..55fdc62 100644 --- a/UpdateSWP.py +++ b/UpdateSWP.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 """ -SkywarnPlus Updater v0.4.2 by Mason Nelson +SkywarnPlus Updater v0.4.3 by Mason Nelson =============================================================================== Script to update SkywarnPlus to the latest version. This script will download the latest version of SkywarnPlus from GitHub, and then merge the existing diff --git a/config.yaml b/config.yaml index 098c7ef..afe120a 100644 --- a/config.yaml +++ b/config.yaml @@ -1,4 +1,4 @@ -# SkywarnPlus v0.4.2 Configuration File +# SkywarnPlus v0.4.3 Configuration File # Author: Mason Nelson (N5LSN/WRKF394) # Please edit this file according to your specific requirements.