enhanceNews

returns a random line from the file
This commit is contained in:
SpudGunMan
2024-12-18 10:53:44 -08:00
parent ad11f787de
commit ca033f024e
4 changed files with 18 additions and 6 deletions
+14 -5
View File
@@ -3,22 +3,31 @@
from modules.log import *
import asyncio
import random
import os
trap_list_filemon = ("readnews",)
def read_file(file_monitor_file_path):
def read_file(file_monitor_file_path, random_line_only=False):
try:
with open(file_monitor_file_path, 'r') as f:
content = f.read()
return content
if random_line_only:
# read a random line from the file
with open(file_monitor_file_path, 'r') as f:
lines = f.readlines()
return random.choice(lines)
else:
# read the whole file
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)
return read_file(news_file_path, read_news_enabled)
def write_news(content, append=False):
# write the news file on demand