Extracted build_menu to separate file

This commit is contained in:
JuliusFreudenberger 2021-02-11 21:54:50 +01:00
parent fbb2c65fd0
commit 724415bcb4
2 changed files with 11 additions and 12 deletions

10
telegram_helpers.py Normal file
View file

@ -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

13
vvs.py
View file

@ -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: