annotate Feed.py @ 47:a8442c3487b5

add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sun, 16 May 2010 08:13:07 +0200
parents aaec263f07ca
children c82f5538733c
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()
47
a8442c3487b5 add an option to Feed that allows loading an entry's link right away instead of displaying a feed's summary
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 35
diff changeset
16 self.auto_load_entry_link = False
2
8a624ee48a74 First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17
8a624ee48a74 First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
18 def __repr__(self):
7
215c34f61e95 Feed.url -> Feed.rss_url
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 4
diff changeset
19 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
20
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 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
22 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
23
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
24 def entriesSortedByUpdateDate(self):
5bb57caa8f66 display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 17
diff changeset
25 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
26 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
27 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
28
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 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
30 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
31 self.next_update = datetime.now() + delta