changeset 206:f74fe7cb5091

when updating feeds, only ever create new Feed objects for entries that are younger than the current expire date. This ensures that we do not see old, read, expired entries again
author dirk
date Sat, 02 Jun 2012 04:30:04 +0200
parents adf7f617bda9
children c694bfb732bc a683c65d324d
files backend/AbstractBackend.py backend/AbstractFeedUpdater.py
diffstat 2 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/backend/AbstractBackend.py	Sat Jun 02 04:24:49 2012 +0200
+++ b/backend/AbstractBackend.py	Sat Jun 02 04:30:04 2012 +0200
@@ -1,6 +1,12 @@
 
 from datetime import datetime, timedelta
 
+def calculateExpireDate(preferences):
+        now = datetime.now()
+        daysToKeepFeedEntries = preferences.daysToKeepFeedEntries()
+        delta = timedelta(days=daysToKeepFeedEntries)
+        return now - delta
+
 class AbstractBackend(object):
     def __init__(self):
         self.feeds = []
@@ -27,10 +33,7 @@
         return self.feedEntries
 
     def _calculateExpireDate(self):
-        now = datetime.now()
-        daysToKeepFeedEntries = self.preferences().daysToKeepFeedEntries()
-        delta = timedelta(days=daysToKeepFeedEntries)
-        return now - delta
+        return calculateExpireDate(self.preferences())
 
     #
     # handling of the selected feed entry
--- a/backend/AbstractFeedUpdater.py	Sat Jun 02 04:24:49 2012 +0200
+++ b/backend/AbstractFeedUpdater.py	Sat Jun 02 04:30:04 2012 +0200
@@ -1,8 +1,9 @@
 
 from datetime import datetime
+from urllib2 import ProxyHandler
+import AbstractBackend
 import feedparser
 import logging
-from urllib2 import ProxyHandler
 
 STATUS_ERROR = 400
 log = logging.getLogger("FeedUpdater")
@@ -42,7 +43,8 @@
     def _processEntries(self, feedDict):
         for entry in feedDict.entries:
             self._normalize(entry)
-            self._processEntry(entry)
+            if not self._isExpired(entry):
+                self._processEntry(entry)
         self._incrementFeedUpdateDate()
 
     def _normalize(self, entry):
@@ -74,6 +76,10 @@
             else:
                 entry.summary = ""
 
+    def _isExpired(self, entry):
+        expireDate = AbstractBackend.calculateExpireDate(self.preferences)
+        return entry.updated_parsed < expireDate
+
     def _processEntry(self, entry):
         raise Exception("_processEntry is abstract, subclasses must override")