Added check for empty query response
Now an unknown station is reported to the user and no longer throws an error.
This commit is contained in:
parent
80c2fb4b9d
commit
9338990491
1 changed files with 4 additions and 1 deletions
5
bot.py
5
bot.py
|
@ -18,7 +18,7 @@ def start(update):
|
||||||
|
|
||||||
def search_station(query):
|
def search_station(query):
|
||||||
request = requests.get("https://efa-api.asw.io/api/v1/station/?search=" + query)
|
request = requests.get("https://efa-api.asw.io/api/v1/station/?search=" + query)
|
||||||
if request.status_code != 200:
|
if request.status_code != 200 and len(request.text) > 2:
|
||||||
return -1
|
return -1
|
||||||
else:
|
else:
|
||||||
return request.json()[0]['stationId']
|
return request.json()[0]['stationId']
|
||||||
|
@ -77,3 +77,6 @@ updater.dispatcher.add_handler(CommandHandler('vvs', get_vvs_departures))
|
||||||
|
|
||||||
updater.start_polling()
|
updater.start_polling()
|
||||||
updater.idle()
|
updater.idle()
|
||||||
|
if query.station_id == -1:
|
||||||
|
update.message.reply_text("No station matching this name found!")
|
||||||
|
return
|
||||||
|
|
Loading…
Reference in a new issue