2018-09-26 17:27:17 +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):
|
|
|
|
@Utils.hook("received.command.wiki|wi", 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
|
|
|
"""
|
2016-05-04 12:30:31 +00:00
|
|
|
page = Utils.get_url(URL_WIKIPEDIA, get_params={
|
|
|
|
"action": "query", "prop": "extracts",
|
2018-08-04 11:48:38 +00:00
|
|
|
"titles": event["args"], "exintro": "",
|
|
|
|
"explaintext": "", "exchars": "500",
|
|
|
|
"redirects": "", "format": "json"}, json=True)
|
2016-05-04 12:30:31 +00:00
|
|
|
if page:
|
2018-08-04 11:48:38 +00:00
|
|
|
pages = page["query"]["pages"]
|
|
|
|
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"]
|
2018-08-04 11:48:38 +00:00
|
|
|
info = info.replace("\n\n", " ").split("\n")[0]
|
2016-05-04 12:30:31 +00:00
|
|
|
event["stdout"].write("%s: %s" % (title, info))
|
|
|
|
else:
|
|
|
|
event["stderr"].write("No results found")
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Failed to load results")
|
|
|
|
|