annotate Feed.py @ 46:03358c113170

Better preferences handling: the GUI's responsibility is to convert the input from the event into a boolean value
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sun, 16 May 2010 07:54:24 +0200
parents aaec263f07ca
children a8442c3487b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
1
35
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
2 from datetime import datetime, timedelta
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
3 import FeedEntry
2
8a624ee48a74 First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4
8a624ee48a74 First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
5 class Feed(object):
16
3ffecc709da9 move fetch logic into Feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 7
diff changeset
6 @staticmethod
3ffecc709da9 move fetch logic into Feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 7
diff changeset
7 def all(session):
3ffecc709da9 move fetch logic into Feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 7
diff changeset
8 return session.query(Feed).order_by(Feed.title).all()
3ffecc709da9 move fetch logic into Feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 7
diff changeset
9
7
215c34f61e95 Feed.url -> Feed.rss_url
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 4
diff changeset
10 def __init__(self, title, rss_url):
215c34f61e95 Feed.url -> Feed.rss_url
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 4
diff changeset
11 self.title = title
215c34f61e95 Feed.url -> Feed.rss_url
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 4
diff changeset
12 self.rss_url = rss_url
35
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
13 # default: update every 60 minutes
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
14 self.update_interval = 60
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
15 self.incrementNextUpdateDate()
2
8a624ee48a74 First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
16
8a624ee48a74 First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17 def __repr__(self):
7
215c34f61e95 Feed.url -> Feed.rss_url
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 4
diff changeset
18 return "<Feed (%d) %s>" % (self.pk, self.title)
17
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
19
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
20 def userPresentableString(self):
5fda8bd94fa8 make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 16
diff changeset
21 return self.title
31
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
22
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
23 def entriesSortedByUpdateDate(self):
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
24 sortedEntries = list(self.entries)
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
25 sortedEntries.sort(FeedEntry.compareByUpdateDate)
35
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
26 return sortedEntries
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
27
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
28 def incrementNextUpdateDate(self):
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
29 delta = timedelta(minutes=self.update_interval)
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 31
diff changeset
30 self.next_update = datetime.now() + delta