From 05e5f83093bf746e0e48617163923025d3b9d14c Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Fri, 13 Jul 2012 00:55:10 +1200 Subject: [PATCH] added reddit plugin from some guy --- plugins/reddit.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 plugins/reddit.py diff --git a/plugins/reddit.py b/plugins/reddit.py new file mode 100755 index 0000000..ae9f20b --- /dev/null +++ b/plugins/reddit.py @@ -0,0 +1,19 @@ +from util import hook, http +import re + +reddit_re = (r'.*((www\.)?reddit\.com/r[^ ]+)', re.I) + +@hook.regex(*reddit_re) +def reddit_url(match): + + thread = http.get_html(match.group(0)) + + title = thread.xpath('//title/text()')[0] + upvotes = thread.xpath("//span[@class='upvotes']/span[@class='number']/text()")[0] + downvotes = thread.xpath("//span[@class='downvotes']/span[@class='number']/text()")[0] + author = thread.xpath("//div[@id='siteTable']//a[contains(@class,'author')]/text()")[0] + timeago = thread.xpath("//div[@id='siteTable']//p[@class='tagline']/time/text()")[0] + comments = thread.xpath("//div[@id='siteTable']//a[@class='comments']/text()")[0] + + return '\x02%s\x02 - posted by \x02%s\x02 %s ago - %s upvotes, %s downvotes - %s' % ( + title, author, timeago, upvotes, downvotes, comments)