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")
|
2020-01-29 17:23:38 +00:00
|
|
|
@utils.hook("received.command.wikipedia")
|
|
|
|
@utils.kwarg("help", "Get information from wikipedia")
|
|
|
|
@utils.spec("!<term>lstring")
|
2016-05-04 12:30:31 +00:00
|
|
|
def wikipedia(self, event):
|
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",
|
2020-01-29 17:23:38 +00:00
|
|
|
"titles": event["spec"][0], "exintro": "", "explaintext": "",
|
2019-11-26 14:18:18 +00:00
|
|
|
"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
|
|
|
|