From 724415bcb42946b0410fe7c2bc1f0986b105d0c2 Mon Sep 17 00:00:00 2001 From: JuliusFreudenberger Date: Thu, 11 Feb 2021 21:54:50 +0100 Subject: [PATCH] Extracted build_menu to separate file --- telegram_helpers.py | 10 ++++++++++ vvs.py | 13 +------------ 2 files changed, 11 insertions(+), 12 deletions(-) create mode 100644 telegram_helpers.py diff --git a/telegram_helpers.py b/telegram_helpers.py new file mode 100644 index 0000000..975e8ef --- /dev/null +++ b/telegram_helpers.py @@ -0,0 +1,10 @@ +def build_menu(buttons: [], + n_cols: int, + header_buttons: [] = None, + footer_buttons: [] = None): + menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)] + if header_buttons: + menu.insert(0, [header_buttons]) + if footer_buttons: + menu.append([footer_buttons]) + return menu diff --git a/vvs.py b/vvs.py index 878516e..dbf65ff 100644 --- a/vvs.py +++ b/vvs.py @@ -3,6 +3,7 @@ import requests from telegram import InlineQueryResultArticle, InputTextMessageContent, InlineKeyboardButton, InlineKeyboardMarkup from exceptions import MultipleStationsFoundError, NoArgError, ServerCommunicationError, StationNotFoundError +from telegram_helpers import build_menu sent_multiple_station_message_ids = dict() @@ -34,18 +35,6 @@ class Query: self.departure_count = int(arguments[argument_names.index(' times ') + 1]) -def build_menu(buttons, - n_cols, - header_buttons=None, - footer_buttons=None): - menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)] - if header_buttons: - menu.insert(0, [header_buttons]) - if footer_buttons: - menu.append([footer_buttons]) - return menu - - def reply_multiple_stations(message, message_text, queried_station, station_list): button_list = [] for station in station_list: