diff options
| author | 2018-08-31 10:50:37 +0100 | |
|---|---|---|
| committer | 2018-08-31 10:50:37 +0100 | |
| commit | abed9cf4ea71dcbad2dd2c049683b8d14b942e09 (patch) | |
| tree | 3e40caf63fa7e1500469f4ad9a0c45c51808aad4 /modules/wolframalpha.py | |
| parent | Fix a copy paste fail in IRCLineHandler that caused PARTs to be handled as QUITs (diff) | |
| signature | ||
Reformat
Diffstat (limited to 'modules/wolframalpha.py')
| -rw-r--r-- | modules/wolframalpha.py | 26 |
1 files changed, 17 insertions, 9 deletions
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="<query>") + ).hook(self.wa, min_args=1, + help= + "Evauate a given string on Wolfram|Alpha", + usage="<query>") 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: |
