From ebf0262607ffc10374181bcd9d39a09cc1d5ce92 Mon Sep 17 00:00:00 2001 From: typoguy Date: Tue, 31 Oct 2017 15:06:04 -0500 Subject: [PATCH 1/2] Create deals.py -- a plugin for listing shopping deals --- plugins/deals.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 plugins/deals.py diff --git a/plugins/deals.py b/plugins/deals.py new file mode 100644 index 000000000..06120153e --- /dev/null +++ b/plugins/deals.py @@ -0,0 +1,32 @@ +from cloudbot import hook +from cloudbot.util import web +import feedparser + +@hook.command('meh', autohelp=False) +def meh(): + '''List the current meh.com deal.''' + url = "https://meh.com/deals.rss" + + feed = feedparser.parse(url) + title = feed.entries[0].title + link = web.try_shorten(feed.entries[0].link) + + return "meh.com: {} ({})".format(title, link) + +@hook.command('slickdeals', autohelp=False) +def slickdeals(): + '''List the top 3 frontpage slickdeals.net deals.''' + url = "https://slickdeals.net/newsearch.php?mode=frontpage&searcharea=deals&searchin=first&rss=1" + + feed = feedparser.parse(url) + + first = feed.entries[0].title, web.try_shorten(feed.entries[0].link) + second = feed.entries[1].title, web.try_shorten(feed.entries[1].link) + third = feed.entries[2].title, web.try_shorten(feed.entries[2].link) + + out = "slickdeals.net: " + out += "{} ({}) • ".format(first[0], first[1]) + out += "{} ({}) • ".format(second[0], second[1]) + out += "{} ({})".format(third[0], third[1]) + + return out From 979aa005be76724bb08e83f61b134f62c1db4add Mon Sep 17 00:00:00 2001 From: typoguy Date: Tue, 31 Oct 2017 20:19:29 -0500 Subject: [PATCH 2/2] Updated deals.py taking into account linuxdaemon's suggestions --- plugins/deals.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/plugins/deals.py b/plugins/deals.py index 06120153e..8b2f0052d 100644 --- a/plugins/deals.py +++ b/plugins/deals.py @@ -2,9 +2,10 @@ from cloudbot.util import web import feedparser + @hook.command('meh', autohelp=False) def meh(): - '''List the current meh.com deal.''' + """- List the current meh.com deal.""" url = "https://meh.com/deals.rss" feed = feedparser.parse(url) @@ -13,20 +14,18 @@ def meh(): return "meh.com: {} ({})".format(title, link) + @hook.command('slickdeals', autohelp=False) def slickdeals(): - '''List the top 3 frontpage slickdeals.net deals.''' + """- List the top 3 frontpage slickdeals.net deals.""" url = "https://slickdeals.net/newsearch.php?mode=frontpage&searcharea=deals&searchin=first&rss=1" feed = feedparser.parse(url) + items = ( + "{} ({})".format(item.title, web.try_shorten(item.link)) + for item in feed.entries[:3] + ) - first = feed.entries[0].title, web.try_shorten(feed.entries[0].link) - second = feed.entries[1].title, web.try_shorten(feed.entries[1].link) - third = feed.entries[2].title, web.try_shorten(feed.entries[2].link) - - out = "slickdeals.net: " - out += "{} ({}) • ".format(first[0], first[1]) - out += "{} ({}) • ".format(second[0], second[1]) - out += "{} ({})".format(third[0], third[1]) + out = "slickdeals.net: " + ' \u2022 '.join(items) return out