From 93389904910e5da91ec365be9f1ee5508e23df11 Mon Sep 17 00:00:00 2001 From: JuliusFreudenberger Date: Tue, 15 Oct 2019 19:26:22 +0200 Subject: [PATCH] Added check for empty query response Now an unknown station is reported to the user and no longer throws an error. --- bot.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 081be22..e71bdba 100644 --- a/bot.py +++ b/bot.py @@ -18,7 +18,7 @@ def start(update): def search_station(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 else: return request.json()[0]['stationId'] @@ -77,3 +77,6 @@ updater.dispatcher.add_handler(CommandHandler('vvs', get_vvs_departures)) updater.start_polling() updater.idle() + if query.station_id == -1: + update.message.reply_text("No station matching this name found!") + return