view backend/sqlalchemy/Feed.py @ 236:c5250fcc3881

remove a workaround along with its wrong explanation
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 26 Jan 2015 13:43:38 +0100
parents 699d8f1cebd4
children
line wrap: on
line source

# -*- coding: utf-8 -*-
import FeedEntry
from datetime import datetime, timedelta

class Feed(object):
    @staticmethod
    def all(session):
        return session.query(Feed).order_by(Feed.title).all()

    def __init__(self, rss_url, title=None):
        self.rss_url = rss_url
        self.title = title
        # default: update every 60 minutes
        self.update_interval = 60
        self.incrementNextUpdateDate()
        self.auto_load_entry_link = False
        self.always_open_in_browser = False

    def __repr__(self):
        return "<Feed (%d) %s>" % (self.pk, self.title)

    def userPresentableString(self):
        return self.title

    def entriesSortedByUpdateDate(self, hideReadEntries=False):
        if hideReadEntries:
            sortedEntries = self._unreadEntries()
        else:
            sortedEntries = list(self.entries)
        sortedEntries.sort(FeedEntry.compareByUpdateDate)
        return sortedEntries

    def _unreadEntries(self):
        retValue = []
        for entry in self.entries:
            if not entry.read:
                retValue.append(entry)
        return retValue

    def incrementNextUpdateDate(self):
        delta = timedelta(minutes=self.update_interval)
        self.next_update = datetime.now() + delta

    def takeChangesFrom(self, changes):
        for key in changes.keys():
            setattr(self, key, changes[key])