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.
This commit is contained in:
Abhijeet Kaur 2017-02-06 21:52:45 +05:30 committed by showell
parent 1ee3e476f3
commit 2282000d78

View file

@ -60,12 +60,12 @@ class WikipediaHandler(object):
logging.error('unsuccessful data') logging.error('unsuccessful data')
return return
search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')
url = 'https://wikipedia.org/wiki/' + search_string
new_content = 'For search term "' + query new_content = 'For search term "' + query
if len(data.json()['query']['search']) == 0: if len(data.json()['query']['search']) == 0:
new_content = 'I am sorry. The search term you provided is not found :slightly_frowning_face:' new_content = 'I am sorry. The search term you provided is not found :slightly_frowning_face:'
else: else:
search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')
url = 'https://en.wikipedia.org/wiki/' + search_string
new_content = new_content + '", ' + url new_content = new_content + '", ' + url
client.send_message(dict( client.send_message(dict(