From ec77c141b97316f9e73426aacaec8e2c91dbf885 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Fri, 19 Oct 2012 07:37:38 +1300 Subject: [PATCH] Add MCWiki plugin (this is basically a clone of drama.py) --- plugins/mcwiki.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 plugins/mcwiki.py diff --git a/plugins/mcwiki.py b/plugins/mcwiki.py new file mode 100755 index 0000000..db7843e --- /dev/null +++ b/plugins/mcwiki.py @@ -0,0 +1,29 @@ +from util import hook, http, text +import re + +api_url = "http://minecraftwiki.net/api.php?action=opensearch" +ed_url = "http://minecraftwiki.net/wiki/" + + +@hook.command +def mcwiki(inp): + "drama -- Gets the first paragraph of" \ + " the Minecraft Wiki article on ." + + j = http.get_json(api_url, search=inp) + print j + if not j[1]: + return "No results found." + article_name = j[1][0].replace(' ', '_').encode('utf8') + + url = ed_url + http.quote(article_name, '') + page = http.get_html(url) + + for p in page.xpath('//div[@class="mw-content-ltr"]/p'): + if p.text_content(): + summary = " ".join(p.text_content().splitlines()) + summary = re.sub("\[\d+\]", "", summary) + summary = text.truncate_str(summary, 250) + return "%s :: \x02%s\x02" % (summary, url) + + return "Unknown Error."