Mercurial > hg > Feedworm
annotate Feed.py @ 78:a728bbc7171e
add some todo items
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sat, 14 Aug 2010 02:54:01 +0200 |
parents | d292ab61ed6f |
children | e59d722439b5 |
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 |
77
d292ab61ed6f
Add another setting to feed: when opening a feed entry in browser, you can force opening it in an external browser now. This is because some sites just crash the QWebView.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
61
diff
changeset
|
17 self.always_open_in_browser = False |
2
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
18 |
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
19 def __repr__(self): |
7 | 20 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
|
21 |
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 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
|
23 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
|
24 |
61
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
25 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
|
26 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
|
27 sortedEntries.sort(FeedEntry.compareByUpdateDate) |
61
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
28 if hideReadEntries: |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
29 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
|
30 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
|
31 |
61
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
32 def _filterReadEntries(self, entries): |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
33 retValue = [] |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
34 for entry in entries: |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
35 if not entry.read: |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
36 retValue.append(entry) |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
37 return retValue |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
38 |
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
|
39 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
|
40 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
|
41 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
|
42 |
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
|
43 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
|
44 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
|
45 entry.markRead() |