Source code for point.plugs.wiki

# p/plugs/wiki.py
#
#

""" query wikipedia. """

## IMPORTS

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

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

## wiki command

url = 'http://nl.wiktionary.org/wiki/Speciaal:Exporteren/%s'

[docs]def do_wiki(event): rest = event.get_rest() if not rest: logging.warn("wiki <item>") ; return what = rest.capitalize() what = quote(what.encode('utf-8')) url2 = url % what txt = str(do_url("GET", url2).read(), "utf-8") if '#REDIRECT' in txt or '#redirect' in txt: redir = ' '.join(txt.split()[1:]) txt = do_url("GET", url % redir) txt = strip_html(strip_wiki(txt)) event.reply(txt)
kernel.cmnds.register("wiki", do_wiki)