comparison 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
comparison
equal deleted inserted replaced
118:0e73adb2dec4 119:04a730f9d07d
1
2 from datetime import datetime, timedelta
3 import FeedEntry
4
5 class Feed(object):
6 @staticmethod
7 def all(session):
8 return session.query(Feed).order_by(Feed.title).all()
9
10 def __init__(self, title, rss_url):
11 self.title = title
12 self.rss_url = rss_url
13 # default: update every 60 minutes
14 self.update_interval = 60
15 self.incrementNextUpdateDate()
16 self.auto_load_entry_link = False
17 self.always_open_in_browser = False
18
19 def __repr__(self):
20 return "<Feed (%d) %s>" % (self.pk, self.title)
21
22 def userPresentableString(self):
23 return self.title
24
25 def entriesSortedByUpdateDate(self, hideReadEntries=False):
26 if hideReadEntries:
27 sortedEntries = self._unreadEntries()
28 else:
29 sortedEntries = list(self.entries)
30 sortedEntries.sort(FeedEntry.compareByUpdateDate)
31 return sortedEntries
32
33 def _unreadEntries(self):
34 retValue = []
35 for entry in self.entries:
36 if not entry.read:
37 retValue.append(entry)
38 return retValue
39
40 def incrementNextUpdateDate(self):
41 delta = timedelta(minutes=self.update_interval)
42 self.next_update = datetime.now() + delta
43
44 def markAllEntriesRead(self):
45 for entry in self.entries:
46 entry.markRead()