view backend/couchdb/Feed.py @ 155:a05719a6175e

move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sat, 27 Aug 2011 08:52:03 +0200
parents b290e29a94b5
children 7d724cf2dcf7
line wrap: on
line source


from couchdb.mapping import BooleanField, DateTimeField, Document, IntegerField, TextField
from datetime import datetime, timedelta

class Feed(Document):
    doctype = TextField(default="feed")
    title = TextField()
    rss_url = TextField()
    update_interval = IntegerField(default=60)
    next_update = DateTimeField()
    auto_load_entry_link = BooleanField(default=False)
    always_open_in_browser = BooleanField(default=False)

    @staticmethod
    def all(database):
        return Feed.view(database, "feedtest/feeds")

    def needsUpdate(self):
        delta = datetime.now() - self.next_update
        return delta.total_seconds() > self._updateIntervalInSeconds()

    def incrementNextUpdateDate(self):
        updateInterval = self._updateIntervalInSeconds()
        delta = timedelta(seconds=updateInterval)
        self.next_update = self.next_update + delta

    def _updateIntervalInSeconds(self):
        return self.update_interval * 60