From 5df86c4773e0c91f12f27a08fd94d47c74eaa56b Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 4 Oct 2012 12:43:40 -0400 Subject: [PATCH] Move parse() to Feed.fetch(). --- rss2email.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) 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): -- 2.26.2