renamed minecraft-related plugins

This commit is contained in:
Luke Rogers 2013-08-01 01:31:48 +12:00
parent 0f217fa3dd
commit 715358298d
5 changed files with 0 additions and 0 deletions

29
plugins/minecraft_wiki.py Executable file
View file

@ -0,0 +1,29 @@
from util import hook, http, text
import re
api_url = "http://minecraftwiki.net/api.php?action=opensearch"
mc_url = "http://minecraftwiki.net/wiki/"
@hook.command
def mcwiki(inp):
"mcwiki <phrase> -- Gets the first paragraph of" \
" the Minecraft Wiki article on <phrase>."
j = http.get_json(api_url, search=inp)
if not j[1]:
return "No results found."
article_name = j[1][0].replace(' ', '_').encode('utf8')
url = mc_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."