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
This commit is contained in:
parent
ccc9577716
commit
69e5285b88
1 changed files with 7 additions and 2 deletions
9
bot.py
9
bot.py
|
@ -25,18 +25,23 @@ def search_station(query):
|
||||||
|
|
||||||
|
|
||||||
def get_vvs_departures(update, context):
|
def get_vvs_departures(update, context):
|
||||||
|
number_departures = 4
|
||||||
|
last_index_string = len(context.args)
|
||||||
if len(context.args) == 0:
|
if len(context.args) == 0:
|
||||||
update.message.reply_text("No argument specified")
|
update.message.reply_text("No argument specified")
|
||||||
return
|
return
|
||||||
|
if context.args[-1].isdigit():
|
||||||
|
number_departures = context.args[-1]
|
||||||
|
last_index_string -= 1
|
||||||
if context.args[0].isdigit():
|
if context.args[0].isdigit():
|
||||||
station_id = context.args[0]
|
station_id = context.args[0]
|
||||||
else:
|
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")
|
request = requests.get("https://efa-api.asw.io/api/v1/station/" + station_id + "/departures")
|
||||||
if request.status_code != 200:
|
if request.status_code != 200:
|
||||||
update.message.reply_text("Error with server communication")
|
update.message.reply_text("Error with server communication")
|
||||||
update.message.reply_text("Next departures:")
|
update.message.reply_text("Next departures:")
|
||||||
for station in request.json()[:4]:
|
for station in request.json()[:int(number_departures)]:
|
||||||
update.message.reply_text(
|
update.message.reply_text(
|
||||||
"Line " + station['number'] + " to \"" + station['direction'] + "\" at "
|
"Line " + station['number'] + " to \"" + station['direction'] + "\" at "
|
||||||
+ station['departureTime']['hour'].zfill(2) + ':' + station['departureTime']['minute'].zfill(2)
|
+ station['departureTime']['hour'].zfill(2) + ':' + station['departureTime']['minute'].zfill(2)
|
||||||
|
|
Loading…
Reference in a new issue