2016-03-30 18:31:23 +00:00
|
|
|
#--require-config wolframalpha-api-key
|
2018-09-02 08:28:55 +00:00
|
|
|
import json
|
2016-03-29 11:56:58 +00:00
|
|
|
import Utils
|
|
|
|
|
2018-09-02 08:28:55 +00:00
|
|
|
URL_WA = "https://api.wolframalpha.com/v1/result"
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
class Module(object):
|
|
|
|
_name = "Wolfram|Alpha"
|
2018-09-02 18:54:45 +00:00
|
|
|
def __init__(self, bot, events, exports):
|
2018-08-31 11:55:52 +00:00
|
|
|
self.bot = bot
|
2018-09-19 12:25:12 +00:00
|
|
|
events.on("received.command").on("wolframalpha", "wa"
|
2016-03-29 11:56:58 +00:00
|
|
|
).hook(self.wa, min_args=1, help=
|
2016-04-06 11:02:44 +00:00
|
|
|
"Evauate a given string on Wolfram|Alpha",
|
|
|
|
usage="<query>")
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
def wa(self, event):
|
2018-09-02 08:28:55 +00:00
|
|
|
code, result = Utils.get_url(URL_WA, get_params={"i": event["args"],
|
2016-03-29 11:56:58 +00:00
|
|
|
"appid": self.bot.config["wolframalpha-api-key"],
|
2018-09-02 08:28:55 +00:00
|
|
|
"reinterpret": "true", "units": "metric"}, code=True)
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-09-02 08:28:55 +00:00
|
|
|
if not result == None:
|
|
|
|
if code == 200:
|
|
|
|
event["stdout"].write("%s: %s" % (event["args"], result))
|
2016-03-29 11:56:58 +00:00
|
|
|
else:
|
2018-09-02 08:28:55 +00:00
|
|
|
event["stdout"].write("No results")
|
2016-03-29 11:56:58 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("Failed to load results")
|