view backend/couchdb/Feed.py @ 206:f74fe7cb5091

when updating feeds, only ever create new Feed objects for entries that are younger than the current expire date. This ensures that we do not see old, read, expired entries again
author dirk
date Sat, 02 Jun 2012 04:30:04 +0200
parents 91a24f499318
children bb3c851b18b1
line wrap: on
line source


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

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, CouchDb.feeds())

    @staticmethod
    def create(url, title=None):
        feed = Feed()
        feed.rss_url = url
        feed.title = title
        return feed

    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 = datetime.now() + delta

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