Mercurial > hg > Feedworm
comparison FeedUpdater.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 | 72dfae865899 |
children | 0604e374c1d6 |
comparison
equal
deleted
inserted
replaced
34:5813e3c10f14 | 35:aaec263f07ca |
---|---|
7 | 7 |
8 STATUS_ERROR = 400 | 8 STATUS_ERROR = 400 |
9 log = logging.getLogger("FeedUpdater") | 9 log = logging.getLogger("FeedUpdater") |
10 | 10 |
11 def updateAllFeeds(session): | 11 def updateAllFeeds(session): |
12 allFeeds = session.query(Feed) | 12 allFeeds = findFeedsToUpdate(session) |
13 for feed in allFeeds: | 13 for feed in allFeeds: |
14 try: | 14 try: |
15 FeedUpdater(session, feed).update() | 15 FeedUpdater(session, feed).update() |
16 except FeedUpdateException: | 16 except FeedUpdateException: |
17 log.warn("problems while updating feed " + feed.rss_url) | 17 log.warn("problems while updating feed " + feed.rss_url) |
18 session.commit() | 18 session.commit() |
19 | |
20 def findFeedsToUpdate(session): | |
21 return session.query(Feed).filter(Feed.next_update < datetime.now()) | |
19 | 22 |
20 def createNewFeed(url, session): | 23 def createNewFeed(url, session): |
21 result = feedparser.parse(url) | 24 result = feedparser.parse(url) |
22 title = result["feed"].title | 25 title = result["feed"].title |
23 newFeed = Feed(title, url) | 26 newFeed = Feed(title, url) |
35 def update(self): | 38 def update(self): |
36 log.info("updating " + self.feed.rss_url) | 39 log.info("updating " + self.feed.rss_url) |
37 result = self.getFeed() | 40 result = self.getFeed() |
38 for entry in result.entries: | 41 for entry in result.entries: |
39 self.processEntry(entry) | 42 self.processEntry(entry) |
43 self.feed.incrementNextUpdateDate() | |
40 | 44 |
41 def getFeed(self): | 45 def getFeed(self): |
42 result = feedparser.parse(self.feed.rss_url) | 46 result = feedparser.parse(self.feed.rss_url) |
43 if result["status"] >= STATUS_ERROR: | 47 if result["status"] >= STATUS_ERROR: |
44 raise FeedUpdateException() | 48 raise FeedUpdateException() |