From e8587da2e54bbbbc7ff74109a24756033c66920e Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Mon, 21 Nov 2011 01:07:02 +1300 Subject: [PATCH] Added drama.py from SkyBot --- plugins/drama.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 plugins/drama.py diff --git a/plugins/drama.py b/plugins/drama.py new file mode 100644 index 0000000..1738e8b --- /dev/null +++ b/plugins/drama.py @@ -0,0 +1,32 @@ +'''Searches Encyclopedia Dramatica and returns the first paragraph of the +article''' + +from util import hook, http + +api_url = "http://encyclopediadramatica.ch/api.php?action=opensearch" +ed_url = "http://encyclopediadramatica.ch/" + + +@hook.command('ed') +@hook.command +def drama(inp): + '''.drama -- gets first paragraph of Encyclopedia Dramatica ''' \ + '''article on ''' + + 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 = ed_url + http.quote(article_name, '') + page = http.get_html(url) + + for p in page.xpath('//div[@id="bodyContent"]/p'): + if p.text_content(): + summary = ' '.join(p.text_content().splitlines()) + if len(summary) > 300: + summary = summary[:summary.rfind(' ', 0, 300)] + "..." + return '%s :: \x02%s\x02' % (summary, url) + + return "error" +