view Feed.py @ 57:254d5b89a6ca

make sqlalchemy logging configurable through the --databaseLogging commandline parameter
author Dirk Olmes <dirk@xanthippe.ping.de>
date Fri, 23 Jul 2010 04:39:08 +0200
parents c82f5538733c
children daa2731967fe
line wrap: on
line source


from datetime import datetime, timedelta
import FeedEntry

class Feed(object):
    @staticmethod
    def all(session):
        return session.query(Feed).order_by(Feed.title).all()
    
    def __init__(self, title, rss_url):
        self.title = title
        self.rss_url = rss_url
        # default: update every 60 minutes
        self.update_interval = 60
        self.incrementNextUpdateDate()
        self.auto_load_entry_link = False

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

    def userPresentableString(self):
        return self.title
    
    def entriesSortedByUpdateDate(self):
        sortedEntries = list(self.entries)
        sortedEntries.sort(FeedEntry.compareByUpdateDate)
        return sortedEntries

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

    def toggleRead(self):
        for entry in self.entries:
            entry.toggleRead()