-
Notifications
You must be signed in to change notification settings - Fork 5
/
wolframalpha.py
69 lines (56 loc) · 2 KB
/
wolframalpha.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# coding=utf-8
# WolframAlpha module for drastikbot2
#
# It makes use of the Short Answers API to get answers for user queries.
#
# You need to use you own AppID to use this module. Find out more:
# http://products.wolframalpha.com/short-answers-api/documentation/
#
# Depends
# -------
# pip: requests
# Copyright (C) 2019, 2021 drastik.org
#
# This file is part of drastikbot.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import urllib.parse
import requests
class Module:
bot_commands = ["wa", "wolfram", "wolframalpha"]
manual = {
"desc": "Get results from the Wolfram|Alpha short answers API.",
"bot_commands": {
"wa": {"usage": lambda x: f"{x}wa <query>",
"alias": ["wolfram", "wolframalpha"]},
"wolfram": {"usage": lambda x: f"{x}wolfram <query>",
"alias": ["w", "wolframalpha"]},
"wolframalpha": {"usage": lambda x: f"{x}wolframalpha <query>",
"alias": ["wolfram", "w"]}
}
}
AppID = "Enter your AppID here"
def short_answers(query):
url = f"http://api.wolframalpha.com/v1/result?appid={AppID}&i={query}"
try:
r = requests.get(url, timeout=10)
except Exception:
return False
return r.text
def main(i, irc):
msgtarget = i.msg.get_msgtarget()
args = i.msg.get_args()
query = urllib.parse.quote_plus(args)
r = short_answers(query)
r = f"Wolfram|Alpha: {r}"
irc.out.notice(msgtarget, r)