mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
RSS: Add feed-specific waitPeriod.
This commit is contained in:
parent
3047ea7acb
commit
82332ff87c
@ -229,6 +229,10 @@ class RSS(callbacks.Plugin):
|
|||||||
conf.registerChannelValue(feed_group, 'announceFormat',
|
conf.registerChannelValue(feed_group, 'announceFormat',
|
||||||
registry.String('', _("""Feed-specific announce format.
|
registry.String('', _("""Feed-specific announce format.
|
||||||
Defaults to supybot.plugins.RSS.announceFormat if empty.""")))
|
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,
|
def register_feed(self, name, url, initial,
|
||||||
plugin_is_loading, announced=[]):
|
plugin_is_loading, announced=[]):
|
||||||
@ -273,7 +277,12 @@ class RSS(callbacks.Plugin):
|
|||||||
|
|
||||||
def is_expired(self, feed):
|
def is_expired(self, feed):
|
||||||
assert 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
|
return feed.last_update < event_horizon
|
||||||
|
|
||||||
###############
|
###############
|
||||||
|
@ -163,6 +163,34 @@ class RSSTestCase(ChannelPluginTestCase):
|
|||||||
self._feedMsg('rss remove xkcdsec')
|
self._feedMsg('rss remove xkcdsec')
|
||||||
feedparser._open_resource = old_open
|
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:
|
if network:
|
||||||
def testRssinfo(self):
|
def testRssinfo(self):
|
||||||
self.assertNotError('rss info %s' % url)
|
self.assertNotError('rss info %s' % url)
|
||||||
|
Loading…
Reference in New Issue
Block a user