changeset 140:e927c6910c38

Automated merge with https://xanthippe.dyndns.org/hg/Feedworm
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 24 Aug 2011 09:39:10 +0200
parents 2642c8d89bdc (current diff) 2cd30af937fa (diff)
children 6ea813cfac33
files
diffstat 2 files changed, 25 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/backend/couchdb/CouchDbBackend.py	Wed Aug 24 09:15:29 2011 +0200
+++ b/backend/couchdb/CouchDbBackend.py	Wed Aug 24 09:39:10 2011 +0200
@@ -1,7 +1,9 @@
 
 from Preferences import Preferences
+from backend.couchdb.Feed import Feed
 import couchdb
 
+
 DATABASE = "feedtest"
 
 class CouchDbBackend(object):
@@ -38,10 +40,15 @@
         raise Exception("not yet implemented")
 
     def updateAllFeeds(self):
-        raise Exception("not yet implemented")
+        # TODO use a view instead of iterating all feeds
+        allFeeds = Feed.all(self.database)
+        for feed in allFeeds:
+            if feed.needsUpdate():
+                print("feed needs update " + str(feed))
 
     def expireFeedEntries(self):
-        raise Exception("not yet implemented")
+        print("Expiring feeds is not yet implemented")
+#        raise Exception("not yet implemented")
 
     def dispose(self):
         # nothing to do here
--- a/backend/couchdb/Feed.py	Wed Aug 24 09:15:29 2011 +0200
+++ b/backend/couchdb/Feed.py	Wed Aug 24 09:39:10 2011 +0200
@@ -1,3 +1,7 @@
+
+from datetime import datetime
+
+DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
 
 class Feed(object):
     @staticmethod
@@ -10,3 +14,15 @@
 
     def __getattr__(self, key):
         return self.row.value[key]
+
+    def needsUpdate(self):
+        updateDate = self._nextUpdateDate()
+        delta = datetime.now() - updateDate
+        return delta.total_seconds() > self._updateIntervalInSeconds()
+
+    def _nextUpdateDate(self):
+        nextUpdateString = self.next_update
+        return datetime.strptime(nextUpdateString, DATE_FORMAT)
+
+    def _updateIntervalInSeconds(self):
+        return self.update_interval * 60