Mercurial > hg > Feedworm
annotate backend/sqlalchemy/Feed.py @ 180:a4832a180c69
allow setting the URL to the database via command line
author | dirk |
---|---|
date | Sat, 10 Sep 2011 04:43:40 +0200 |
parents | a3c945ce434c |
children | 7157bfd3f4d4 |
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() |
99
e59d722439b5
filter out read entries first before sorting
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
77
diff
changeset
|
9 |
167
a3c945ce434c
adjust the sqlalchemy backend to the changes in AbstractFeedUpdater
dirk
parents:
124
diff
changeset
|
10 def __init__(self, rss_url, title=None): |
a3c945ce434c
adjust the sqlalchemy backend to the changes in AbstractFeedUpdater
dirk
parents:
124
diff
changeset
|
11 self.rss_url = rss_url |
7 | 12 self.title = title |
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 |
99
e59d722439b5
filter out read entries first before sorting
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
77
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): |
99
e59d722439b5
filter out read entries first before sorting
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
77
diff
changeset
|
26 if hideReadEntries: |
e59d722439b5
filter out read entries first before sorting
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
77
diff
changeset
|
27 sortedEntries = self._unreadEntries() |
e59d722439b5
filter out read entries first before sorting
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
77
diff
changeset
|
28 else: |
e59d722439b5
filter out read entries first before sorting
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
77
diff
changeset
|
29 sortedEntries = list(self.entries) |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
17
diff
changeset
|
30 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
|
31 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
|
32 |
99
e59d722439b5
filter out read entries first before sorting
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
77
diff
changeset
|
33 def _unreadEntries(self): |
61
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
34 retValue = [] |
99
e59d722439b5
filter out read entries first before sorting
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
77
diff
changeset
|
35 for entry in self.entries: |
61
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
36 if not entry.read: |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
37 retValue.append(entry) |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
38 return retValue |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
59
diff
changeset
|
39 |
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
|
40 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
|
41 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
|
42 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
|
43 |
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 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
|
45 for entry in self.entries: |
124
a4b2077c9603
editing a feed's properties is implemented through the backend now
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
119
diff
changeset
|
46 entry.markRead() |
167
a3c945ce434c
adjust the sqlalchemy backend to the changes in AbstractFeedUpdater
dirk
parents:
124
diff
changeset
|
47 |
a3c945ce434c
adjust the sqlalchemy backend to the changes in AbstractFeedUpdater
dirk
parents:
124
diff
changeset
|
48 def takeChangesFrom(self, changes): |
a3c945ce434c
adjust the sqlalchemy backend to the changes in AbstractFeedUpdater
dirk
parents:
124
diff
changeset
|
49 for key in changes.keys(): |
a3c945ce434c
adjust the sqlalchemy backend to the changes in AbstractFeedUpdater
dirk
parents:
124
diff
changeset
|
50 setattr(self, key, changes[key]) |