contrib_bots: Fix bare except clause.

This commit is contained in:
Tommy Ip 2017-01-08 16:09:23 +00:00 committed by Tim Abbott
parent 6302f0d645
commit 3cea2b5f1c

View file

@ -43,17 +43,18 @@ class WikipediaHandler(object):
return is_wikipedia return is_wikipedia
def handle_message(self, message, client, state_handler): def handle_message(self, message, client, state_handler):
original_content = message['content'] query = message['content']
for prefix in ['@wikipedia', '@wiki']: for prefix in ['@wikipedia', '@wiki']:
if original_content.startswith(prefix): if query.startswith(prefix):
original_content = original_content[len(prefix)+1:] query = query[len(prefix)+1:]
break break
query_wiki_link = 'https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=' query_wiki_link = ('https://en.wikipedia.org/w/api.php?action=query&'
'list=search&srsearch=%s&format=json' % (query,))
try: try:
data = requests.get(query_wiki_link + original_content + '&format=json') data = requests.get(query_wiki_link)
except: except requests.exceptions.RequestException:
logging.error('broken link') logging.error('broken link')
return return
@ -63,7 +64,7 @@ class WikipediaHandler(object):
search_string = data.json()['query']['search'][0]['title'].replace(' ', '_') search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')
url = 'https://wikipedia.org/wiki/' + search_string url = 'https://wikipedia.org/wiki/' + search_string
new_content = 'For search term "' + original_content 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: