Source code for bot.plugs.wiki

# bot/plugs/wiki.py
#
#

""" query wikipedia. """

## IMPORTS

from bot.utils import error, from_enc, do_url, strip_html, strip_wiki
from bot import kernel, Object

from urllib.parse import quote
import logging
import cgi
import re

# Wiki class

[docs]class Wiki(Object): pass ## wiki command
[docs]def do_wiki(event): if not event.rest: logging.warn("wiki <item>") ; return what = event.rest.capitalize() url = 'http://en.wikipedia.org/wiki/Special:Export/%s' % quote(what.encode('utf-8')) o = Wiki() data = do_url("GET", url).read() txt = strip_html(strip_wiki(str(data, "utf-8"))) o.txt = txt event.reply(txt)
kernel.register("wiki", do_wiki)