Mercurial > hg > Feedworm
comparison Feed.py @ 35:aaec263f07ca
Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Wed, 05 May 2010 03:07:59 +0200 |
parents | 5bb57caa8f66 |
children | a8442c3487b5 |
comparison
equal
deleted
inserted
replaced
34:5813e3c10f14 | 35:aaec263f07ca |
---|---|
1 | 1 |
2 from datetime import datetime, timedelta | |
2 import FeedEntry | 3 import FeedEntry |
3 | 4 |
4 class Feed(object): | 5 class Feed(object): |
5 @staticmethod | 6 @staticmethod |
6 def all(session): | 7 def all(session): |
7 return session.query(Feed).order_by(Feed.title).all() | 8 return session.query(Feed).order_by(Feed.title).all() |
8 | 9 |
9 def __init__(self, title, rss_url): | 10 def __init__(self, title, rss_url): |
10 self.title = title | 11 self.title = title |
11 self.rss_url = rss_url | 12 self.rss_url = rss_url |
13 # default: update every 60 minutes | |
14 self.update_interval = 60 | |
15 self.incrementNextUpdateDate() | |
12 | 16 |
13 def __repr__(self): | 17 def __repr__(self): |
14 return "<Feed (%d) %s>" % (self.pk, self.title) | 18 return "<Feed (%d) %s>" % (self.pk, self.title) |
15 | 19 |
16 def userPresentableString(self): | 20 def userPresentableString(self): |
18 | 22 |
19 def entriesSortedByUpdateDate(self): | 23 def entriesSortedByUpdateDate(self): |
20 sortedEntries = list(self.entries) | 24 sortedEntries = list(self.entries) |
21 sortedEntries.sort(FeedEntry.compareByUpdateDate) | 25 sortedEntries.sort(FeedEntry.compareByUpdateDate) |
22 return sortedEntries | 26 return sortedEntries |
27 | |
28 def incrementNextUpdateDate(self): | |
29 delta = timedelta(minutes=self.update_interval) | |
30 self.next_update = datetime.now() + delta |