comparison backend/AbstractFeedUpdater.py @ 160:86f828096aaf

Do not fetch and parse the feed twice when creating a new one. Pass the parsed info into the update method instead to reuse.
author dirk
date Mon, 29 Aug 2011 03:07:50 +0200
parents 74217db92993
children 04c3b9796b89
comparison
equal deleted inserted replaced
159:7d724cf2dcf7 160:86f828096aaf
13 ''' 13 '''
14 14
15 def __init__(self, feed): 15 def __init__(self, feed):
16 self.feed = feed 16 self.feed = feed
17 17
18 def update(self): 18 def update(self, feedDict=None):
19 log.info("updating " + self.feed.rss_url) 19 log.info("updating " + self.feed.rss_url)
20 result = self._retrieveFeed() 20 if feedDict is None:
21 for entry in result.entries: 21 result = self._retrieveFeed()
22 self._normalize(entry) 22 else:
23 self._processEntry(entry) 23 result = feedDict
24 self._incrementFeedUpdateDate() 24 self._processEntries(result)
25 25
26 def _retrieveFeed(self): 26 def _retrieveFeed(self):
27 result = feedparser.parse(self.feed.rss_url) 27 result = feedparser.parse(self.feed.rss_url)
28 # bozo flags if a feed is well-formed. 28 # bozo flags if a feed is well-formed.
29 # if result["bozo"] > 0: 29 # if result["bozo"] > 0:
30 # raise FeedUpdateException() 30 # raise FeedUpdateException()
31 status = result["status"] 31 status = result["status"]
32 if status >= STATUS_ERROR: 32 if status >= STATUS_ERROR:
33 raise FeedUpdateException("HTTP status " + str(status)) 33 raise FeedUpdateException("HTTP status " + str(status))
34 return result 34 return result
35
36 def _processEntries(self, feedDict):
37 for entry in feedDict.entries:
38 self._normalize(entry)
39 self._processEntry(entry)
40 self._incrementFeedUpdateDate()
35 41
36 def _normalize(self, entry): 42 def _normalize(self, entry):
37 if not hasattr(entry, "id"): 43 if not hasattr(entry, "id"):
38 entry.id = entry.link 44 entry.id = entry.link
39 if not hasattr(entry, "updated_parsed"): 45 if not hasattr(entry, "updated_parsed"):