diff options
| author | 2018-08-31 10:51:47 +0100 | |
|---|---|---|
| committer | 2018-08-31 10:51:47 +0100 | |
| commit | 90ce92dc39395444862edfc7946ef7a1195f2464 (patch) | |
| tree | 6832c146a15879df292d265083bfe5795cbdfa69 /modules/wolframalpha.py | |
| parent | Reformat (diff) | |
Revert "Reformat"
This reverts commit abed9cf
Diffstat (limited to 'modules/wolframalpha.py')
| -rw-r--r-- | modules/wolframalpha.py | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/modules/wolframalpha.py b/modules/wolframalpha.py index 89f3527d..059408d7 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,39 +6,31 @@ 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: |
