annotate backend/couchdb/Feed.py @ 214:b0de75d57e78

Merge with 1ac0b8e2feae3bd8336dded8247ae201b13d9ca1
author dirk
date Sat, 04 May 2013 06:23:20 +0200
parents 91a24f499318
children bb3c851b18b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents: 166
diff changeset
4 import CouchDb
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
5
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
6 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
7 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
8 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
9 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
10 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
11 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
12 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
13 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
14
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 @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
16 def all(database):
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents: 166
diff changeset
17 return Feed.view(database, CouchDb.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
18
161
2940e74c9663 Creating a feed via the GUI works now.
dirk
parents: 159
diff changeset
19 @staticmethod
166
04c3b9796b89 feedparser uses the proxy now if one is configured. To implement this the FeedUpdater had to change a bit - sqlalchemy backend is not yet refactored.
dirk
parents: 161
diff changeset
20 def create(url, title=None):
161
2940e74c9663 Creating a feed via the GUI works now.
dirk
parents: 159
diff changeset
21 feed = Feed()
2940e74c9663 Creating a feed via the GUI works now.
dirk
parents: 159
diff changeset
22 feed.rss_url = url
2940e74c9663 Creating a feed via the GUI works now.
dirk
parents: 159
diff changeset
23 feed.title = title
2940e74c9663 Creating a feed via the GUI works now.
dirk
parents: 159
diff changeset
24 return feed
2940e74c9663 Creating a feed via the GUI works now.
dirk
parents: 159
diff changeset
25
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
26 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
27 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
28 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
29
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
30 def incrementNextUpdateDate(self):
144
74217db92993 updating feeds on the couchdb backend works now
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 139
diff changeset
31 updateInterval = self._updateIntervalInSeconds()
74217db92993 updating feeds on the couchdb backend works now
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 139
diff changeset
32 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
33 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
34
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 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
36 return self.update_interval * 60