From 69e5285b88c4e173fa1a730cde0c3bb6b29ab7e7 Mon Sep 17 00:00:00 2001 From: JuliusFreudenberger Date: Mon, 14 Oct 2019 13:22:56 +0200 Subject: [PATCH] Added ability to give desired number of departures the input is tested for the last argument: if the it is a number, it is used as this number --- bot.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 84c3bae..ad556b7 100644 --- a/bot.py +++ b/bot.py @@ -25,18 +25,23 @@ def search_station(query): def get_vvs_departures(update, context): + number_departures = 4 + last_index_string = len(context.args) if len(context.args) == 0: update.message.reply_text("No argument specified") return + if context.args[-1].isdigit(): + number_departures = context.args[-1] + last_index_string -= 1 if context.args[0].isdigit(): station_id = context.args[0] else: - station_id = search_station(' '.join(context.args)) + station_id = search_station(' '.join(context.args[0:last_index_string])) request = requests.get("https://efa-api.asw.io/api/v1/station/" + station_id + "/departures") if request.status_code != 200: update.message.reply_text("Error with server communication") update.message.reply_text("Next departures:") - for station in request.json()[:4]: + for station in request.json()[:int(number_departures)]: update.message.reply_text( "Line " + station['number'] + " to \"" + station['direction'] + "\" at " + station['departureTime']['hour'].zfill(2) + ':' + station['departureTime']['minute'].zfill(2)