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)