Mercurial > hg > Feedworm
diff backend/sqlalchemy/Feed.py @ 119:04a730f9d07d backend
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sun, 21 Aug 2011 03:55:16 +0200 |
parents | Feed.py@e59d722439b5 |
children | a4b2077c9603 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backend/sqlalchemy/Feed.py Sun Aug 21 03:55:16 2011 +0200 @@ -0,0 +1,46 @@ + +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 + 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 markAllEntriesRead(self): + for entry in self.entries: + entry.markRead() \ No newline at end of file