changeset 209:a683c65d324d

Automated merge with https://xanthippe.dyndns.org/hg/Feedworm
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 04 Jun 2012 08:35:17 +0200
parents f74fe7cb5091 (diff) a2552f1e450e (current diff)
children e2c70c92da02
files
diffstat 3 files changed, 31 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/backend/AbstractBackend.py	Fri Jun 01 17:29:43 2012 +0200
+++ b/backend/AbstractBackend.py	Mon Jun 04 08:35:17 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	Fri Jun 01 17:29:43 2012 +0200
+++ b/backend/AbstractFeedUpdater.py	Mon Jun 04 08:35:17 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")
 
--- a/backend/couchdb/CouchDb.py	Fri Jun 01 17:29:43 2012 +0200
+++ b/backend/couchdb/CouchDb.py	Mon Jun 04 08:35:17 2012 +0200
@@ -3,16 +3,19 @@
 
 database_url = None
 database = "feedworm"
+design_document = database
 
 def init():
     args = _parseArguments()
     _setDatabaseName(args)
     _setDatabaseUrl(args)
+    _setDesignDocument(args)
 
 def _parseArguments():
     parser = ArgumentParser()
     parser.add_argument("--dbname", nargs="?", help="Name of the database")
     parser.add_argument("--dburl", nargs="?", help="URL of the database")
+    parser.add_argument("--designdoc", nargs="?", help="name of the feedworm design document")
     return parser.parse_known_args()
 
 def _setDatabaseName(args):
@@ -27,27 +30,33 @@
         global database_url
         database_url = dburl
 
+def _setDesignDocument(args):
+    designDocument = args[0].designdoc
+    if designDocument is not None:
+        global design_document
+        design_document = designDocument
+
 #
 # accessor methods for the various views
 #
 
 def feedEntriesByFeed():
-    return database + "/feedEntries_by_feed"
+    return design_document + "/feedEntries_by_feed"
 
 def unreadFeedEntriesByFeed():
-    return database + "/unread_feedEntries_by_feed"
+    return design_document + "/unread_feedEntries_by_feed"
 
 def feeds():
-    return database + "/feeds"
+    return design_document + "/feeds"
 
 def feedEntryByLink():
-    return database + "/feedEntry_by_link"
+    return design_document + "/feedEntry_by_link"
 
 def preference():
-    return database + "/preference"
+    return design_document + "/preference"
 
 def readFeedEntriesByCreateDate():
-    return database + "/read_feedEntries_by_create_date"
+    return design_document + "/read_feedEntries_by_create_date"
 
 def feedsWithUnreadEntries():
-    return database + "/feeds_with_unread_entries"
+    return design_document + "/feeds_with_unread_entries"