From 65b1ece86fe8148a592c68503d586627a1f5fe3e Mon Sep 17 00:00:00 2001 From: Luke Robles <98352913+lrobles-iterable@users.noreply.github.com> Date: Thu, 6 Oct 2022 14:58:58 -0700 Subject: [PATCH] fixing the ask method --- app/questions.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/questions.py b/app/questions.py index 8effd439..a49be59e 100755 --- a/app/questions.py +++ b/app/questions.py @@ -13,17 +13,15 @@ def answer_question(message): If no answer is found, tries wikipedia. If that fails, apologizes """ - if len(message.split()) > 1: - client = wolframalpha.Client(os.getenv("wolfram_token")) - question = " ".join(message.split()[1:]) + client = wolframalpha.Client(os.getenv("wolfram_token")) + try: + res = client.query(message) + return next(res.results).text + except Exception: try: - res = client.query(question) - return next(res.results).text + return wikipedia.summary(message, sentences=5) except Exception: - try: - return wikipedia.summary(question, sentences=5) - except Exception: - return "Sorry, I'm unable to answer that" + return "Sorry, I'm unable to answer that" return help_methods.get_help_message("message")