diff backend/couchdb/Feed.py @ 139:2cd30af937fa

add the required methods for determining if a feed needs to be updated
author Dirk Olmes <dirk@xanthippe.ping.de>
date Tue, 23 Aug 2011 16:02:35 +0200
parents 7217b060b39c
children 74217db92993
line wrap: on
line diff
--- a/backend/couchdb/Feed.py	Tue Aug 23 14:36:58 2011 +0200
+++ b/backend/couchdb/Feed.py	Tue Aug 23 16:02:35 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