mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 11:12:47 +01:00
RSS: add option display headline timestamp.
This commit is contained in:
parent
78659113c1
commit
af1931b3db
@ -74,6 +74,12 @@ conf.registerChannelValue(RSS, 'showLinks',
|
|||||||
along with the title of the feed when the rss command is called.
|
along with the title of the feed when the rss command is called.
|
||||||
supybot.plugins.RSS.announce.showLinks affects whether links will be
|
supybot.plugins.RSS.announce.showLinks affects whether links will be
|
||||||
listed when a feed is automatically announced."""))
|
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',
|
conf.registerGlobalValue(RSS, 'defaultNumberOfHeadlines',
|
||||||
registry.PositiveInteger(1, """Indicates how many headlines an rss feed
|
registry.PositiveInteger(1, """Indicates how many headlines an rss feed
|
||||||
will output by default, if no number is provided."""))
|
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
|
registry.Boolean(False, """Determines whether the bot will list the link
|
||||||
along with the title of the feed when a feed is automatically
|
along with the title of the feed when a feed is automatically
|
||||||
announced."""))
|
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',
|
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."""))
|
in seconds. Headline cache is used to avoid re-announcing old news."""))
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,23 +139,24 @@ class RSS(callbacks.Plugin):
|
|||||||
self.releaseLock(url)
|
self.releaseLock(url)
|
||||||
time.sleep(0.1) # So other threads can run.
|
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 = []
|
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 headline[1]:
|
||||||
if self.registryValue('stripRedirect'):
|
if self.registryValue('stripRedirect'):
|
||||||
h = re.sub('^.*http://', 'http://', headline[1])
|
link = ' <%s>' % (re.sub('^.*http://', 'http://', headline[1]),)
|
||||||
else:
|
else:
|
||||||
h = headline[1]
|
link = ' <%s>' % (headline[1],)
|
||||||
newheadlines.append(format('%s %u',
|
if self.registryValue(dateconfig, channel):
|
||||||
headline[0],
|
if headline[2]:
|
||||||
h.encode('utf-8')))
|
pubDate = ' [%s]' % (headline[2],)
|
||||||
else:
|
newheadlines.append(format('%s%s%s',
|
||||||
newheadlines.append(format('%s', headline[0]))
|
headline[0],
|
||||||
else:
|
link.encode('utf-8'),
|
||||||
for headline in headlines:
|
pubDate))
|
||||||
newheadlines = [format('%s', h[0]) for h in headlines]
|
|
||||||
return newheadlines
|
return newheadlines
|
||||||
|
|
||||||
def _newHeadlines(self, irc, channels, name, url):
|
def _newHeadlines(self, irc, channels, name, url):
|
||||||
@ -172,7 +173,7 @@ class RSS(callbacks.Plugin):
|
|||||||
#oldresults = self.cachedFeeds[url]
|
#oldresults = self.cachedFeeds[url]
|
||||||
#oldheadlines = self.getHeadlines(oldresults)
|
#oldheadlines = self.getHeadlines(oldresults)
|
||||||
oldheadlines = self.cachedHeadlines[url]
|
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:
|
except KeyError:
|
||||||
oldheadlines = []
|
oldheadlines = []
|
||||||
newresults = self.getFeed(url)
|
newresults = self.getFeed(url)
|
||||||
@ -317,8 +318,9 @@ class RSS(callbacks.Plugin):
|
|||||||
for d in feed['items']:
|
for d in feed['items']:
|
||||||
if 'title' in d:
|
if 'title' in d:
|
||||||
title = conv(d['title'])
|
title = conv(d['title'])
|
||||||
link = d.get('link') # defaults to None
|
link = d.get('link')
|
||||||
headlines.append((title, link, t))
|
pubDate = d.get('pubDate', d.get('updated'))
|
||||||
|
headlines.append((title, link, pubDate, t))
|
||||||
return headlines
|
return headlines
|
||||||
|
|
||||||
def makeFeedCommand(self, name, url):
|
def makeFeedCommand(self, name, url):
|
||||||
@ -430,7 +432,7 @@ class RSS(callbacks.Plugin):
|
|||||||
if not headlines:
|
if not headlines:
|
||||||
irc.error('Couldn\'t get RSS feed.')
|
irc.error('Couldn\'t get RSS feed.')
|
||||||
return
|
return
|
||||||
headlines = self.buildHeadlines(headlines, channel, 'showLinks')
|
headlines = self.buildHeadlines(headlines, channel, 'showLinks', 'showPubDate')
|
||||||
if n:
|
if n:
|
||||||
headlines = headlines[:n]
|
headlines = headlines[:n]
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user