From 2282000d78e52e8b3bd562e2585497bec645bfee Mon Sep 17 00:00:00 2001 From: Abhijeet Kaur Date: Mon, 6 Feb 2017 21:52:45 +0530 Subject: [PATCH] bug fix: Fix wikipedia bot in case no results are found. Incorrect Index access in wikipedia.py resulted in IndexError and wikipedia bot to crash for few queries. This causes the bug to be fixed. Replaced url to avoid 2 redirects and enhance performance. Fixes: #3508. --- contrib_bots/bots/wikipedia/wikipedia.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib_bots/bots/wikipedia/wikipedia.py b/contrib_bots/bots/wikipedia/wikipedia.py index 7faaf65..4162ad3 100644 --- a/contrib_bots/bots/wikipedia/wikipedia.py +++ b/contrib_bots/bots/wikipedia/wikipedia.py @@ -60,12 +60,12 @@ class WikipediaHandler(object): logging.error('unsuccessful data') return - search_string = data.json()['query']['search'][0]['title'].replace(' ', '_') - url = 'https://wikipedia.org/wiki/' + search_string new_content = 'For search term "' + query if len(data.json()['query']['search']) == 0: new_content = 'I am sorry. The search term you provided is not found :slightly_frowning_face:' else: + search_string = data.json()['query']['search'][0]['title'].replace(' ', '_') + url = 'https://en.wikipedia.org/wiki/' + search_string new_content = new_content + '", ' + url client.send_message(dict(