comparison 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
comparison
equal deleted inserted replaced
137:5b131f82057d 139:2cd30af937fa
1
2 from datetime import datetime
3
4 DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
1 5
2 class Feed(object): 6 class Feed(object):
3 @staticmethod 7 @staticmethod
4 def all(database): 8 def all(database):
5 viewResults = database.view("feedtest/feeds") 9 viewResults = database.view("feedtest/feeds")
8 def __init__(self, row): 12 def __init__(self, row):
9 self.row = row 13 self.row = row
10 14
11 def __getattr__(self, key): 15 def __getattr__(self, key):
12 return self.row.value[key] 16 return self.row.value[key]
17
18 def needsUpdate(self):
19 updateDate = self._nextUpdateDate()
20 delta = datetime.now() - updateDate
21 return delta.total_seconds() > self._updateIntervalInSeconds()
22
23 def _nextUpdateDate(self):
24 nextUpdateString = self.next_update
25 return datetime.strptime(nextUpdateString, DATE_FORMAT)
26
27 def _updateIntervalInSeconds(self):
28 return self.update_interval * 60