Mercurial > hg > Feedworm
view backend/couchdb/Feed.py @ 145:71c5dc02ff87
move the code from FeedList into the backend class
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Thu, 25 Aug 2011 05:39:03 +0200 |
parents | 74217db92993 |
children | b290e29a94b5 |
line wrap: on
line source
from datetime import datetime, timedelta DATE_FORMAT = "%Y-%m-%d %H:%M:%S" class Feed(object): @staticmethod def all(database): viewResults = database.view("feedtest/feeds") return [Feed(row) for row in viewResults] def __init__(self, row): self.row = row 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 incrementedUpdateDate(self): updateDate = self._nextUpdateDate() updateInterval = self._updateIntervalInSeconds() delta = timedelta(seconds=updateInterval) return updateDate + delta def _nextUpdateDate(self): nextUpdateString = self.next_update return datetime.strptime(nextUpdateString, DATE_FORMAT) def _updateIntervalInSeconds(self): return self.update_interval * 60