2019-05-25 20:40:06 +00:00
|
|
|
#--depends-on commands
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-05-04 12:30:31 +00:00
|
|
|
|
|
|
|
URL_WIKIPEDIA = "https://en.wikipedia.org/w/api.php"
|
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2018-10-10 09:42:41 +00:00
|
|
|
@utils.hook("received.command.wi", alias_of="wiki")
|
2019-06-10 22:06:47 +00:00
|
|
|
@utils.hook("received.command.wiki", alias_of="wikipedia")
|
|
|
|
@utils.hook("received.command.wikipedia", min_args=1)
|
2016-05-04 12:30:31 +00:00
|
|
|
def wikipedia(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Get information from wikipedia
|
|
|
|
:usage: <term>
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-12-11 22:26:38 +00:00
|
|
|
page = utils.http.request(URL_WIKIPEDIA, get_params={
|
2019-11-26 14:18:18 +00:00
|
|
|
"action": "query", "prop": "extracts|info", "inprop": "url",
|
|
|
|
"titles": event["args"], "exintro": "", "explaintext": "",
|
|
|
|
"exchars": "500", "redirects": "", "format": "json"}).json()
|
|
|
|
|
2016-05-04 12:30:31 +00:00
|
|
|
if page:
|
2019-11-26 14:14:38 +00:00
|
|
|
pages = page["query"]["pages"]
|
2018-08-04 11:48:38 +00:00
|
|
|
article = list(pages.items())[0][1]
|
|
|
|
if not "missing" in article:
|
2016-05-04 12:30:31 +00:00
|
|
|
title, info = article["title"], article["extract"]
|
2019-11-26 14:18:18 +00:00
|
|
|
title = article["title"]
|
|
|
|
info = utils.parse.line_normalise(article["extract"])
|
|
|
|
url = article["fullurl"]
|
|
|
|
|
|
|
|
event["stdout"].write("%s: %s - %s" % (title, info, url))
|
2016-05-04 12:30:31 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("No results found")
|
|
|
|
else:
|
2019-11-18 12:06:59 +00:00
|
|
|
raise utils.EventResultsError()
|
2016-05-04 12:30:31 +00:00
|
|
|
|