Mercurial > hg > Feedworm
annotate backend/couchdb/Feed.py @ 162:ab2b26412b77
setting a feed's properties via the GUI works now
author | dirk |
---|---|
date | Mon, 29 Aug 2011 03:11:47 +0200 |
parents | 2940e74c9663 |
children | 04c3b9796b89 |
rev | line source |
---|---|
139
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
136
diff
changeset
|
1 |
147
b290e29a94b5
use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
144
diff
changeset
|
2 from couchdb.mapping import BooleanField, DateTimeField, Document, IntegerField, TextField |
144
74217db92993
updating feeds on the couchdb backend works now
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
139
diff
changeset
|
3 from datetime import datetime, timedelta |
139
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
136
diff
changeset
|
4 |
147
b290e29a94b5
use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
144
diff
changeset
|
5 class Feed(Document): |
b290e29a94b5
use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
144
diff
changeset
|
6 doctype = TextField(default="feed") |
b290e29a94b5
use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
144
diff
changeset
|
7 title = TextField() |
b290e29a94b5
use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
144
diff
changeset
|
8 rss_url = TextField() |
b290e29a94b5
use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
144
diff
changeset
|
9 update_interval = IntegerField(default=60) |
b290e29a94b5
use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
144
diff
changeset
|
10 next_update = DateTimeField() |
b290e29a94b5
use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
144
diff
changeset
|
11 auto_load_entry_link = BooleanField(default=False) |
b290e29a94b5
use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
144
diff
changeset
|
12 always_open_in_browser = BooleanField(default=False) |
136
7217b060b39c
implement a Feed class that can be used to query feed and that wraps view results
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
13 |
7217b060b39c
implement a Feed class that can be used to query feed and that wraps view results
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
14 @staticmethod |
7217b060b39c
implement a Feed class that can be used to query feed and that wraps view results
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
15 def all(database): |
147
b290e29a94b5
use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
144
diff
changeset
|
16 return Feed.view(database, "feedtest/feeds") |
139
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
136
diff
changeset
|
17 |
161 | 18 @staticmethod |
19 def create(url, title): | |
20 feed = Feed() | |
21 feed.rss_url = url | |
22 feed.title = title | |
23 return feed | |
24 | |
139
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
136
diff
changeset
|
25 def needsUpdate(self): |
147
b290e29a94b5
use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
144
diff
changeset
|
26 delta = datetime.now() - self.next_update |
139
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
136
diff
changeset
|
27 return delta.total_seconds() > self._updateIntervalInSeconds() |
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
136
diff
changeset
|
28 |
147
b290e29a94b5
use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
144
diff
changeset
|
29 def incrementNextUpdateDate(self): |
144
74217db92993
updating feeds on the couchdb backend works now
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
139
diff
changeset
|
30 updateInterval = self._updateIntervalInSeconds() |
74217db92993
updating feeds on the couchdb backend works now
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
139
diff
changeset
|
31 delta = timedelta(seconds=updateInterval) |
159
7d724cf2dcf7
after a feed update, calculate a feed's update date from the current date, not the original next update date
dirk
parents:
147
diff
changeset
|
32 self.next_update = datetime.now() + delta |
139
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
136
diff
changeset
|
33 |
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
136
diff
changeset
|
34 def _updateIntervalInSeconds(self): |
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
136
diff
changeset
|
35 return self.update_interval * 60 |