Mercurial > hg > Feedworm
annotate Feed.py @ 68:525a52169f60
Make FeedEntry table object available in Mapping to use it to expire old, read feed entries.
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Tue, 10 Aug 2010 03:32:29 +0200 |
parents | db35ab7753f0 |
children | d292ab61ed6f |
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 | 10 def __init__(self, title, rss_url): |
11 self.title = title | |
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 | 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 |
61
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
24 def entriesSortedByUpdateDate(self, hideReadEntries=False): |
31
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) |
61
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
27 if hideReadEntries: |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
28 return self._filterReadEntries(sortedEntries) |
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
|
29 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
|
30 |
61
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
31 def _filterReadEntries(self, entries): |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
32 retValue = [] |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
33 for entry in entries: |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
34 if not entry.read: |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
35 retValue.append(entry) |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
36 return retValue |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
37 |
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
|
38 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
|
39 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
|
40 self.next_update = datetime.now() + delta |
56
c82f5538733c
add a menu item to mark all entries in a feed as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
47
diff
changeset
|
41 |
59
daa2731967fe
Marking all articles in a feed as read doesn't toggle any more ... it marks all articles as read.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
56
diff
changeset
|
42 def markAllEntriesRead(self): |
56
c82f5538733c
add a menu item to mark all entries in a feed as read
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
47
diff
changeset
|
43 for entry in self.entries: |
59
daa2731967fe
Marking all articles in a feed as read doesn't toggle any more ... it marks all articles as read.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
56
diff
changeset
|
44 entry.markRead() |