bitbot-3.11-fork/modules/wolframalpha.py

28 lines
936 B
Python
Raw Normal View History

#--require-config wolframalpha-api-key
import json
2016-03-29 11:56:58 +00:00
import Utils
URL_WA = "https://api.wolframalpha.com/v1/result"
2016-03-29 11:56:58 +00:00
class Module(object):
_name = "Wolfram|Alpha"
def __init__(self, bot, events, exports):
self.bot = bot
events.on("received.command").on("wolframalpha", "wa"
2016-03-29 11:56:58 +00:00
).hook(self.wa, min_args=1, help=
"Evauate a given string on Wolfram|Alpha",
usage="<query>")
2016-03-29 11:56:58 +00:00
def wa(self, event):
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"],
"reinterpret": "true", "units": "metric"}, code=True)
2016-03-29 11:56:58 +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:
event["stdout"].write("No results")
2016-03-29 11:56:58 +00:00
else:
event["stderr"].write("Failed to load results")