From 11a6dc3cf0c3ada543fab17200f540983d88e729 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 15 Mar 2025 17:31:44 -0700 Subject: [PATCH] UTF-8-4-Windows Co-Authored-By: dj505 --- modules/filemon.py | 8 ++++---- modules/games/hamtest.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/filemon.py b/modules/filemon.py index 41cd3c2..783d0b3 100644 --- a/modules/filemon.py +++ b/modules/filemon.py @@ -17,12 +17,12 @@ def read_file(file_monitor_file_path, random_line_only=False): return "🐝buzz 💐buzz buzz🍯" if random_line_only: # read a random line from the file - with open(file_monitor_file_path, 'r') as f: + with open(file_monitor_file_path, 'r', encoding='utf-8') as f: lines = f.readlines() return random.choice(lines) else: # read the whole file - with open(file_monitor_file_path, 'r') as f: + with open(file_monitor_file_path, 'r', encoding='utf-8') as f: content = f.read() return content except Exception as e: @@ -37,7 +37,7 @@ def read_news(): def write_news(content, append=False): # write the news file on demand try: - with open(news_file_path, 'a' if append else 'w') as f: + with open(news_file_path, 'a' if append else 'w', encoding='utf-8') as f: f.write(content) logger.info(f"FileMon: Updated {news_file_path}") return True @@ -76,7 +76,7 @@ def call_external_script(message, script="script/runShell.sh"): logger.warning(f"FileMon: Script not found: {script_path}") return "sorry I can't do that" - output = os.popen(f"bash {script_path} {message}").read() + output = os.popen(f"bash {script_path} {message}", encoding='utf-8').read() return output except Exception as e: logger.warning(f"FileMon: Error calling external script: {e}") diff --git a/modules/games/hamtest.py b/modules/games/hamtest.py index 45d6a6e..60d840a 100644 --- a/modules/games/hamtest.py +++ b/modules/games/hamtest.py @@ -20,7 +20,7 @@ class HamTest: def load_questions(self): for level in ['technician', 'general', 'extra']: try: - with open(f'{os.path.dirname(__file__)}/../../data/hamradio/{level}.json') as f: + with open(f'{os.path.dirname(__file__)}/../../data/hamradio/{level}.json', encoding='utf-8') as f: self.questions[level] = json.load(f) except FileNotFoundError: logger.error(f"File not found: ../../data/hamradio/{level}.json")