From 235c8c4dbbc01562c8657cec8c50f8976dc9738b Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sat, 18 Dec 2021 15:49:03 -0500 Subject: [PATCH] [F] Fix database loading --- menubot/menubot.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/menubot/menubot.py b/menubot/menubot.py index 4057556..fd12cfa 100644 --- a/menubot/menubot.py +++ b/menubot/menubot.py @@ -116,13 +116,6 @@ if __name__ == '__main__': dispatcher: Dispatcher = updater.dispatcher # Database - database: list[tuple[int, list[str]]] - if os.path.isfile(db_path): - with open(db_path, 'r', encoding='utf-8') as f: - database = json.load(f) - else: - database = [] - def save_db(): with open(db_path, 'w', encoding='utf-8') as f: json.dump(database, f) @@ -132,6 +125,14 @@ if __name__ == '__main__': menu_helper(d[0], d[1]) schedule.every().day.at('07:00').do(func) + database: list[tuple[int, list[str]]] + if os.path.isfile(db_path): + with open(db_path, 'r', encoding='utf-8') as f: + database = json.load(f) + save_db() + else: + database = [] + def r(u: Update, msg: str, md=True): updater.bot.sendMessage(chat_id=u.effective_chat.id, text=msg, parse_mode='Markdown' if md else None) @@ -192,6 +193,7 @@ if __name__ == '__main__': r(u, '*Available Menus:* \n' + '\n'.join(m.keys()) + '\n\nNext: /menu ') def menu_helper(chat_id: int, args: list[str]): + print('Menu helper called.', chat_id, args) hall, menu = args[:2] cats = args[2:] hall, menu, m = get_menu_cats(hall, menu, cats)