RSS: Add feed-specific waitPeriod.

This commit is contained in:
Valentin Lorentz 2015-09-23 11:05:25 +02:00
parent 3047ea7acb
commit 82332ff87c
2 changed files with 38 additions and 1 deletions

View File

@ -229,6 +229,10 @@ class RSS(callbacks.Plugin):
conf.registerChannelValue(feed_group, 'announceFormat',
registry.String('', _("""Feed-specific announce format.
Defaults to supybot.plugins.RSS.announceFormat if empty.""")))
conf.registerGlobalValue(feed_group, 'waitPeriod',
registry.NonNegativeInteger(0, _("""If set to a non-zero
value, overrides supybot.plugins.RSS.waitPeriod for this
particular feed.""")))
def register_feed(self, name, url, initial,
plugin_is_loading, announced=[]):
@ -273,7 +277,12 @@ class RSS(callbacks.Plugin):
def is_expired(self, feed):
assert feed
event_horizon = time.time() - self.registryValue('waitPeriod')
period = self.registryValue('waitPeriod')
if feed.name != feed.url: # Named feed
specific_period = self.registryValue('feeds.%s.waitPeriod' % feed.name)
if specific_period:
period = specific_period
event_horizon = time.time() - period
return feed.last_update < event_horizon
###############

View File

@ -163,6 +163,34 @@ class RSSTestCase(ChannelPluginTestCase):
self._feedMsg('rss remove xkcdsec')
feedparser._open_resource = old_open
def testFeedSpecificWaitPeriod(self):
old_open = feedparser._open_resource
feedparser._open_resource = constant(xkcd_old)
try:
self.assertNotError('rss add xkcd1 http://xkcd.com/rss.xml')
self.assertNotError('rss announce add xkcd1')
self.assertNotError('rss add xkcd2 http://xkcd.com/rss.xml&foo')
self.assertNotError('rss announce add xkcd2')
self.assertNotError(' ')
self.assertNotError(' ')
with conf.supybot.plugins.RSS.feeds.xkcd1.waitPeriod.context(1):
time.sleep(1.1)
self.assertNoResponse(' ')
self.assertNoResponse(' ')
feedparser._open_resource = constant(xkcd_new)
self.assertNoResponse(' ')
time.sleep(1.1)
self.assertRegexp(' ', 'xkcd1.*Chaos')
self.assertNoResponse(' ')
time.sleep(1.1)
self.assertNoResponse(' ')
finally:
self._feedMsg('rss announce remove xkcd1')
self._feedMsg('rss remove xkcd1')
self._feedMsg('rss announce remove xkcd2')
self._feedMsg('rss remove xkcd2')
feedparser._open_resource = old_open
if network:
def testRssinfo(self):
self.assertNotError('rss info %s' % url)