comparison backend/couchdb/FeedUpdater.py @ 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.
author dirk
date Sat, 03 Sep 2011 04:12:35 +0200
parents 2940e74c9663
children a9ba3e3a9a9a
comparison
equal deleted inserted replaced
165:a5bda54309ba 166:04c3b9796b89
1 1
2 from Feed import Feed
3 from FeedEntry import FeedEntry 2 from FeedEntry import FeedEntry
4 from backend.AbstractFeedUpdater import AbstractFeedUpdater 3 from backend.AbstractFeedUpdater import AbstractFeedUpdater
5 import logging 4 import logging
6 import feedparser
7 5
8 log = logging.getLogger("FeedUpdater") 6 log = logging.getLogger("FeedUpdater")
9 7
10 class FeedUpdater(AbstractFeedUpdater): 8 class FeedUpdater(AbstractFeedUpdater):
11 @staticmethod 9 def __init__(self, database, preferences):
12 def createFeed(url, database): 10 AbstractFeedUpdater.__init__(self, preferences)
13 feedDict = feedparser.parse(url)
14 if feedDict.has_key("title"):
15 title = feedDict["feed"].title
16 else:
17 title = url
18 feed = Feed.create(url, title)
19 feed.store(database)
20 FeedUpdater(feed, database).update(feedDict)
21
22 def __init__(self, feed, database):
23 AbstractFeedUpdater.__init__(self, feed)
24 self.database = database 11 self.database = database
25 12
26 def _processEntry(self, entry): 13 def _processEntry(self, entry):
27 feedEntry = FeedEntry.findByLink(entry.link, self.database) 14 feedEntry = FeedEntry.findByLink(entry.link, self.database)
28 if feedEntry is None: 15 if feedEntry is None:
39 feedEntry.store(self.database) 26 feedEntry.store(self.database)
40 27
41 def _incrementFeedUpdateDate(self): 28 def _incrementFeedUpdateDate(self):
42 self.feed.incrementNextUpdateDate() 29 self.feed.incrementNextUpdateDate()
43 self.feed.store(self.database) 30 self.feed.store(self.database)
31
32 def _setFeedTitle(self, feedDict):
33 oldTitle = self.feed.title
34 AbstractFeedUpdater._setFeedTitle(self, feedDict)
35 if oldTitle != self.feed.title:
36 self.feed.store(self.database)