comparison backend/AbstractFeedUpdater.py @ 167:a3c945ce434c

adjust the sqlalchemy backend to the changes in AbstractFeedUpdater
author dirk
date Mon, 05 Sep 2011 19:39:08 +0200
parents 04c3b9796b89
children 2f2016a10f7d
comparison
equal deleted inserted replaced
166:04c3b9796b89 167:a3c945ce434c
11 ''' 11 '''
12 Abstract base class for FeedUpdater implementations - handles all the parsing of the feed. 12 Abstract base class for FeedUpdater implementations - handles all the parsing of the feed.
13 Subclasses need to implement creating and storing the new feed entries. 13 Subclasses need to implement creating and storing the new feed entries.
14 ''' 14 '''
15 15
16 @staticmethod
17 def parseFeed(url):
18 proxy = ProxyHandler( {"http":"http://your.proxy.here:8080/"} )
19 return feedparser.parse(url, handlers = [proxy])
20
21 def __init__(self, preferences): 16 def __init__(self, preferences):
22 self.preferences = preferences 17 self.preferences = preferences
23 18
24 def update(self, feed): 19 def update(self, feed):
25 self.feed = feed 20 self.feed = feed
26 log.info("updating " + feed.rss_url) 21 log.info("updating " + feed.rss_url)
27 result = self._retrieveFeed() 22 result = self._retrieveFeed()
23 self._setFeedTitle(result)
28 self._processEntries(result) 24 self._processEntries(result)
29 self._setFeedTitle(result)
30 25
31 def _retrieveFeed(self): 26 def _retrieveFeed(self):
32 if self.preferences.isProxyConfigured(): 27 if self.preferences.isProxyConfigured():
33 proxyUrl = "http://%s:%i" % (self.preferences.proxyHost(), self.preferences.proxyPort()) 28 proxyUrl = "http://%s:%i" % (self.preferences.proxyHost(), self.preferences.proxyPort())
34 proxyHandler = ProxyHandler({"http" : proxyUrl}) 29 proxyHandler = ProxyHandler({"http" : proxyUrl})
35 result = feedparser.parse(self.feed.rss_url, handlers=[proxyHandler]) 30 result = feedparser.parse(self.feed.rss_url, handlers=[proxyHandler])
36 else: 31 else:
32 # when updating to python3 see http://code.google.com/p/feedparser/issues/detail?id=260
37 result = feedparser.parse(self.feed.rss_url) 33 result = feedparser.parse(self.feed.rss_url)
38 # bozo flags if a feed is well-formed. 34 # bozo flags if a feed is well-formed.
39 # if result["bozo"] > 0: 35 # if result["bozo"] > 0:
40 # raise FeedUpdateException() 36 # raise FeedUpdateException()
41 status = result["status"] 37 status = result["status"]