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:
parent
1ee3e476f3
commit
2282000d78
|
@ -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(
|
||||||
|
|
Loading…
Reference in a new issue