Add MCWiki plugin (this is basically a clone of drama.py)
This commit is contained in:
parent
70e22af2cd
commit
ec77c141b9
1 changed files with 29 additions and 0 deletions
29
plugins/mcwiki.py
Executable file
29
plugins/mcwiki.py
Executable file
|
@ -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 <phrase> -- Gets the first paragraph of" \
|
||||||
|
" the Minecraft Wiki article on <phrase>."
|
||||||
|
|
||||||
|
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."
|
Reference in a new issue