diff --git a/plugins/RSS/config.py b/plugins/RSS/config.py index e4fe98faa..11d201441 100644 --- a/plugins/RSS/config.py +++ b/plugins/RSS/config.py @@ -74,6 +74,12 @@ conf.registerChannelValue(RSS, 'showLinks', along with the title of the feed when the rss command is called. supybot.plugins.RSS.announce.showLinks affects whether links will be listed when a feed is automatically announced.""")) +conf.registerChannelValue(RSS, 'showPubDate', + registry.Boolean(False, """Determines whether the bot will list the + publication datetime stamp along with the title of the feed when the rss + command is called. + supybot.plugins.RSS.announce.showPubDate affects whether this will be + listed when a feed is automatically announced.""")) conf.registerGlobalValue(RSS, 'defaultNumberOfHeadlines', registry.PositiveInteger(1, """Indicates how many headlines an rss feed will output by default, if no number is provided.""")) @@ -95,8 +101,12 @@ conf.registerChannelValue(RSS.announce, 'showLinks', registry.Boolean(False, """Determines whether the bot will list the link along with the title of the feed when a feed is automatically announced.""")) +conf.registerChannelValue(RSS.announce, 'showPubDate', + registry.Boolean(False, """Determines whether the bot will list the + publication datetime stamp along with the title of the feed when a feed + is automatically announced.""")) conf.registerGlobalValue(RSS.announce, 'cachePeriod', - registry.PositiveInteger(86400, """Maximum age of cached RSS headlines, + registry.PositiveInteger(604800, """Maximum age of cached RSS headlines, in seconds. Headline cache is used to avoid re-announcing old news.""")) diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index 8ef5a4a11..f8c3394f5 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -139,23 +139,24 @@ class RSS(callbacks.Plugin): self.releaseLock(url) time.sleep(0.1) # So other threads can run. - def buildHeadlines(self, headlines, channel, config='announce.showLinks'): + def buildHeadlines(self, headlines, channel, linksconfig='announce.showLinks', dateconfig='announce.showPubDate'): newheadlines = [] - if self.registryValue(config, channel): - for headline in headlines: + for headline in headlines: + link = '' + pubDate = '' + if self.registryValue(linksconfig, channel): if headline[1]: if self.registryValue('stripRedirect'): - h = re.sub('^.*http://', 'http://', headline[1]) + link = ' <%s>' % (re.sub('^.*http://', 'http://', headline[1]),) else: - h = headline[1] - newheadlines.append(format('%s %u', - headline[0], - h.encode('utf-8'))) - else: - newheadlines.append(format('%s', headline[0])) - else: - for headline in headlines: - newheadlines = [format('%s', h[0]) for h in headlines] + link = ' <%s>' % (headline[1],) + if self.registryValue(dateconfig, channel): + if headline[2]: + pubDate = ' [%s]' % (headline[2],) + newheadlines.append(format('%s%s%s', + headline[0], + link.encode('utf-8'), + pubDate)) return newheadlines def _newHeadlines(self, irc, channels, name, url): @@ -172,7 +173,7 @@ class RSS(callbacks.Plugin): #oldresults = self.cachedFeeds[url] #oldheadlines = self.getHeadlines(oldresults) oldheadlines = self.cachedHeadlines[url] - oldheadlines = filter(lambda x: t - x[2] < self.registryValue('announce.cachePeriod'), oldheadlines) + oldheadlines = filter(lambda x: t - x[3] < self.registryValue('announce.cachePeriod'), oldheadlines) except KeyError: oldheadlines = [] newresults = self.getFeed(url) @@ -317,8 +318,9 @@ class RSS(callbacks.Plugin): for d in feed['items']: if 'title' in d: title = conv(d['title']) - link = d.get('link') # defaults to None - headlines.append((title, link, t)) + link = d.get('link') + pubDate = d.get('pubDate', d.get('updated')) + headlines.append((title, link, pubDate, t)) return headlines def makeFeedCommand(self, name, url): @@ -430,7 +432,7 @@ class RSS(callbacks.Plugin): if not headlines: irc.error('Couldn\'t get RSS feed.') return - headlines = self.buildHeadlines(headlines, channel, 'showLinks') + headlines = self.buildHeadlines(headlines, channel, 'showLinks', 'showPubDate') if n: headlines = headlines[:n] else: