From fd22566ddfadbc79fa32aa80191d8bfbe822126e Mon Sep 17 00:00:00 2001 From: Pedro Rey Anca Date: Mon, 10 Feb 2025 13:59:52 +0100 Subject: [PATCH] Fix file read-write --- bot/bot_listen.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bot/bot_listen.py b/bot/bot_listen.py index d6f3327..c00b898 100644 --- a/bot/bot_listen.py +++ b/bot/bot_listen.py @@ -1,4 +1,6 @@ from telethon import TelegramClient, events +import json + import config from utils import parse_menu_message, InvalidMenuMessageError @@ -15,10 +17,14 @@ async def handler(event): except InvalidMenuMessageError as e: print(e) return - with open(config.menu_history_file_path, "rw", encoding='utf-8') as f: + + with open(config.menu_history_file_path, "r", encoding='utf-8') as f: menus = json.load(f) - menus[msg.date.strftime("%d-%m-%Y")] = {"courses": courses, - "message": msg.message} + + menus[msg.date.strftime("%d-%m-%Y")] = {"courses": courses, + "message": msg.message} + + with open(config.menu_history_file_path, "w", encoding='utf-8') as f: json.dump(menus, f, ensure_ascii=False, indent=4)