From 40834eeb93d869dfe10ac5f1f417bb343a3cdfea Mon Sep 17 00:00:00 2001 From: pictuga Date: Sat, 8 Nov 2014 20:31:29 +0100 Subject: [PATCH] Split After into Before/After Needed since a bunch of options needed to be run before the actual fetching (cause no-one needs to fetch the articles of to-be-dropped items) --- morss/morss.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/morss/morss.py b/morss/morss.py index b38450c..18a9cb6 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -668,7 +668,7 @@ def Gather(rss, url, cache, options): return rss -def After(rss, options): +def Before(rss, options): for i, item in enumerate(list(rss.items)): if options.smart and options.last: if item.time < feeds.parse_time(options.last) and i > 2: @@ -688,6 +688,11 @@ def After(rss, options): item.remove() continue + return rss + + +def After(rss, options): + for i, item in enumerate(list(rss.items)): if item.desc and item.content: if options.clip: item.content = item.desc + "

* * *


" + item.content @@ -714,6 +719,10 @@ def After(rss, options): if item.content: item.content = conv.handle(item.content) + return rss + + +def Format(rss, options): if options.callback: if re.match(r'^[a-zA-Z0-9\.]+$', options.callback) is not None: return '%s(%s)' % (options.callback, rss.tojson()) @@ -739,9 +748,11 @@ def process(url, cache=None, options=None): options = Options(options) url, cache = Init(url, cache, options) rss = Fetch(url, cache, options) + rss = Before(rss, options) rss = Gather(rss, url, cache, options) + rss = After(rss, options) - return After(rss, options) + return Format(rss, options) def cgi_app(environ, start_response): @@ -815,8 +826,10 @@ def cgi_app(environ, start_response): start_response(headers['status'], headers.items()) + rss = Before(rss, options) rss = Gather(rss, url, cache, options) - out = After(rss, options) + rss = After(rss, options) + out = Format(rss, options) if not options.silent: return out @@ -872,8 +885,10 @@ def cli_app(): url, cache = Init(url, os.path.expanduser('~/.cache/morss'), options) rss = Fetch(url, cache, options) + rss = Before(rss, options) rss = Gather(rss, url, cache, options) - out = After(rss, options) + rss = After(rss, options) + out = Format(rss, options) if not options.silent: print out