From: W. Trevor King Date: Thu, 4 Oct 2012 16:43:40 +0000 (-0400) Subject: Move parse() to Feed.fetch(). X-Git-Tag: v3.0~72^2~41 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5df86c4773e0c91f12f27a08fd94d47c74eaa56b;p=rss2email.git Move parse() to Feed.fetch(). --- diff --git a/rss2email.py b/rss2email.py index 56f53ab..b4125b8 100755 --- a/rss2email.py +++ b/rss2email.py @@ -786,6 +786,28 @@ class Feed (object): self.name = name self.section = 'feed.{}'.format(self.name) + def fetch(self): + """Fetch and parse a feed using feedparser. + + >>> feed = Feed( + ... name='test-feed', + ... url='http://feeds.feedburner.com/allthingsrss/hJBr') + >>> parsed = feed.fetch() + >>> parsed.status + 200 + """ + if self.section in self.config: + config = self.config[self.section] + else: + config = self.config['DEFAULT'] + proxy = config['proxy'] + timeout = config.getint('feed-timeout') + kwargs = {} + if proxy: + kwargs['handlers'] = [_urllib_request.ProxyHandler({'http':proxy})] + f = TimeLimitedFunction(timeout, _feedparser.parse) + return f(self.url, self.etag, modified=self.modified, **kwargs) + class Feeds (list): """Utility class for rss2email activity. @@ -914,15 +936,6 @@ class Feeds (list): _pickle.dump(list(self), open(self.datafile, 'wb')) -#@timelimit(FEED_TIMEOUT) -def parse(url, etag, modified): - if PROXY == '': - return feedparser.parse(url, etag, modified) - else: - proxy = urllib2.ProxyHandler( {"http":PROXY} ) - return feedparser.parse(url, etag, modified, handlers = [proxy]) - - ### Program Functions ### def add(*args):