From 24bcd5cbf9cb4278b65432948bddd4998c4fbb8c Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 5 Dec 2024 11:08:11 -0800 Subject: [PATCH] readNews on demand return of the file news.txt for readnews onair --- README.md | 6 +++++- config.template | 4 +++- mesh_bot.py | 3 +++ modules/filemon.py | 23 +++++++++++++++-------- modules/settings.py | 4 +++- modules/system.py | 5 ++++- news.txt | 1 + 7 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 news.txt diff --git a/README.md b/README.md index a5ba158..bb80205 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Welcome to the Mesh Bot project! This feature-rich bot is designed to enhance yo ### File Monitor Alerts - **File Mon**: Monitor a flat/text file for changes, brodcast the contents of the message to mesh channel. +- **News File**: on request of news the contents of the file is returned. ### Data Reporting - **HTML Generator**: Visualize bot traffic and data flows with a built-in HTML generator for [data reporting](logs/README.md). @@ -216,11 +217,14 @@ signalCycleLimit = 5 ### File Monitoring Some dev notes for ideas of use + ```ini [fileMon] -enabled = True +filemon_enabled = True file_path = alert.txt broadcastCh = 2,4 +enable_read_news = False +news_file_path = news.txt ``` #### NOAA EAS To Alert on Mesh with the NOAA EAS API you can set the channels and enable, checks every 30min diff --git a/config.template b/config.template index fb9d2ec..0da141c 100644 --- a/config.template +++ b/config.template @@ -147,9 +147,11 @@ signalCooldown = 5 signalCycleLimit = 5 [fileMon] -enabled = False +filemon_enabled = False file_path = alert.txt broadcastCh = 2 +enable_read_news = False +news_file_path = news.txt [messagingSettings] # delay in seconds for response to avoid message collision diff --git a/mesh_bot.py b/mesh_bot.py index 6e9e53d..0844c64 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -57,6 +57,7 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n "ping": lambda: handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, channel_number), "pinging": lambda: handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, channel_number), "pong": lambda: "🏓PING!!🛜", + "readnews": lambda: read_news(), "rlist": lambda: handle_repeaterQuery(message_from_id, deviceID, channel_number), "sitrep": lambda: handle_lheard(message, message_from_id, deviceID, isDM), "solar": lambda: drap_xray_conditions() + "\n" + solar_conditions(), @@ -1059,6 +1060,8 @@ async def start_rx(): logger.debug(f"System: Radio Detection Enabled using rigctld at {rigControlServerAddress} brodcasting to channels: {sigWatchBroadcastCh} for {get_freq_common_name(get_hamlib('f'))}") if file_monitor_enabled: logger.debug(f"System: File Monitor Enabled for {file_monitor_file_path}, broadcasting to channels: {file_monitor_broadcastCh}") + if read_news_enabled: + logger.debug(f"System: File Monitor News Reader Enabled for {news_file_path}") if wxAlertBroadcastEnabled: logger.debug(f"System: Weather Alert Broadcast Enabled on channels {wxAlertBroadcastChannel}") if scheduler_enabled: diff --git a/modules/filemon.py b/modules/filemon.py index 48b2478..a4861a1 100644 --- a/modules/filemon.py +++ b/modules/filemon.py @@ -5,15 +5,22 @@ from modules.log import * import asyncio import os +trap_list_filemon = ("readnews",) + +def read_file(file_monitor_file_path): + try: + with open(file_monitor_file_path, 'r') as f: + content = f.read() + return content + except Exception as e: + logger.warning(f"FileMon: Error reading file: {file_monitor_file_path}") + return None + +def read_news(): + # read the news file on demand + return read_file(news_file_path) + async def watch_file(): - def read_file(file_monitor_file_path): - try: - with open(file_monitor_file_path, 'r') as f: - content = f.read() - return content - except Exception as e: - logger.warning(f"FileMon: Error reading file: {file_monitor_file_path}") - return None if not os.path.exists(file_monitor_file_path): return None diff --git a/modules/settings.py b/modules/settings.py index 4f6ef19..28682b7 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -176,9 +176,11 @@ try: signalCycleLimit = config['radioMon'].getint('signalCycleLimit', 5) # default 5 cycles, used with SIGNAL_COOLDOWN # file monitor - file_monitor_enabled = config['fileMon'].getboolean('enabled', False) + file_monitor_enabled = config['fileMon'].getboolean('filemon_enabled', False) file_monitor_file_path = config['fileMon'].get('file_path', 'alert.txt') # default alert.txt file_monitor_broadcastCh = config['fileMon'].getint('broadcastCh', 2) # default 2 + read_news_enabled = config['fileMon'].getboolean('enable_read_news', False) # default disabled + news_file_path = config['fileMon'].get('news_file_path', 'news.txt') # default news.txt # games game_hop_limit = config['messagingSettings'].getint('game_hop_limit', 5) # default 3 hops diff --git a/modules/system.py b/modules/system.py index cd8f087..f35a87b 100644 --- a/modules/system.py +++ b/modules/system.py @@ -174,8 +174,11 @@ if radio_detection_enabled: from modules.radio import * # from the spudgunman/meshing-around repo # File Monitor Configuration -if file_monitor_enabled: +if file_monitor_enabled or read_news_enabled: from modules.filemon import * # from the spudgunman/meshing-around repo + if read_news_enabled: + trap_list = trap_list + trap_list_filemon # items readnews + help_message = help_message + ", readmail" # BLE dual interface prevention if interface1_type == 'ble' and interface2_type == 'ble': diff --git a/news.txt b/news.txt new file mode 100644 index 0000000..6f3fc71 --- /dev/null +++ b/news.txt @@ -0,0 +1 @@ +no new news is good news! \ No newline at end of file