Merge branch 'restructure_vvs'

This commit is contained in:
JuliusFreudenberger 2021-02-11 21:55:44 +01:00
commit d734f355f7
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 telegram import InlineQueryResultArticle, InputTextMessageContent, InlineKeyboardButton, InlineKeyboardMarkup
from exceptions import MultipleStationsFoundError, NoArgError, ServerCommunicationError, StationNotFoundError from exceptions import MultipleStationsFoundError, NoArgError, ServerCommunicationError, StationNotFoundError
from telegram_helpers import build_menu
sent_multiple_station_message_ids = dict() sent_multiple_station_message_ids = dict()
@ -34,18 +35,6 @@ class Query:
self.departure_count = int(arguments[argument_names.index(' times ') + 1]) 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): def reply_multiple_stations(message, message_text, queried_station, station_list):
button_list = [] button_list = []
for station in station_list: for station in station_list: