From abed9cf4ea71dcbad2dd2c049683b8d14b942e09 Mon Sep 17 00:00:00 2001 From: dngfx Date: Fri, 31 Aug 2018 10:50:37 +0100 Subject: Reformat --- modules/wolframalpha.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'modules/wolframalpha.py') diff --git a/modules/wolframalpha.py b/modules/wolframalpha.py index 059408d7..89f3527d 100644 --- a/modules/wolframalpha.py +++ b/modules/wolframalpha.py @@ -1,4 +1,4 @@ -#--require-config wolframalpha-api-key +# --require-config wolframalpha-api-key import re import Utils @@ -6,31 +6,39 @@ import Utils URL_WA = "http://api.wolframalpha.com/v2/query" REGEX_CHARHEX = re.compile("\\\\:(\S{4})") + class Module(object): _name = "Wolfram|Alpha" + def __init__(self, bot): bot.events.on("received").on("command").on("wolframalpha", "wa" - ).hook(self.wa, min_args=1, help= - "Evauate a given string on Wolfram|Alpha", - usage="") + ).hook(self.wa, min_args=1, + help= + "Evauate a given string on Wolfram|Alpha", + usage="") self.bot = bot def wa(self, event): soup = Utils.get_url(URL_WA, get_params={"input": event["args"], - "appid": self.bot.config["wolframalpha-api-key"], - "format": "plaintext", "reinterpret": "true"}, soup=True) + "appid": self.bot.config[ + "wolframalpha-api-key"], + "format": "plaintext", + "reinterpret": "true"}, + soup=True) if soup: if int(soup.find("queryresult").get("numpods")) > 0: input = soup.find(id="Input").find("subpod").find("plaintext" - ).text + ).text answered = False for pod in soup.find_all("pod"): if pod.get("primary") == "true": answer = pod.find("subpod").find("plaintext") text = "(%s) %s" % (input.replace(" | ", ": "), - answer.text.strip().replace(" | ", ": " - ).replace("\n", " | ").replace("\r", "")) + answer.text.strip().replace(" | ", + ": " + ).replace( + "\n", " | ").replace("\r", "")) while True: match = re.search(REGEX_CHARHEX, text) if match: -- cgit v1.3.1-10-gc9f91