Fixed bugz0rs in RSS's announcements.

This commit is contained in:
Jeremy Fincher 2004-02-10 03:14:46 +00:00
parent 0c2de453f2
commit 20285ae546

View File

@ -96,6 +96,7 @@ class RSS(callbacks.Privmsg):
self.feedNames = sets.Set() self.feedNames = sets.Set()
self.lastRequest = {} self.lastRequest = {}
self.cachedFeeds = {} self.cachedFeeds = {}
self.currentlyDownloading = sets.Set()
for (name, url) in registry._cache.iteritems(): for (name, url) in registry._cache.iteritems():
name = name.lower() name = name.lower()
if name.startswith('supybot.plugins.rss.feeds.'): if name.startswith('supybot.plugins.rss.feeds.'):
@ -151,20 +152,27 @@ class RSS(callbacks.Privmsg):
def willGetNewFeed(self, url): def willGetNewFeed(self, url):
now = time.time() now = time.time()
wait = self.registryValue('waitPeriod') wait = self.registryValue('waitPeriod')
if url in self.currentlyDownloading:
return False
if url not in self.lastRequest or now - self.lastRequest[url] > wait: if url not in self.lastRequest or now - self.lastRequest[url] > wait:
return True return True
else: else:
return False return False
def getFeed(self, url): def getFeed(self, url):
if self.willGetNewFeed(url): if self.willGetNewFeed(url):
try: try:
self.log.info('Downloading new feed from <%s>', url) self.currentlyDownloading.add(url)
results = rssparser.parse(url) try:
except sgmllib.SGMLParseError: self.log.info('Downloading new feed from <%s>', url)
self.log.exception('Uncaught exception from rssparser:') results = rssparser.parse(url)
raise callbacks.Error, 'Invalid (unparseable) RSS feed.' except sgmllib.SGMLParseError:
self.cachedFeeds[url] = results self.log.exception('Uncaught exception from rssparser:')
self.lastRequest[url] = time.time() raise callbacks.Error, 'Invalid (unparseable) RSS feed.'
self.cachedFeeds[url] = results
self.lastRequest[url] = time.time()
finally:
self.currentlyDownloading.discard(url)
return self.cachedFeeds[url] return self.cachedFeeds[url]
def getHeadlines(self, feed): def getHeadlines(self, feed):