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)
master
pictuga 2014-11-08 20:31:29 +01:00
parent f20fb9cdf6
commit 40834eeb93
1 changed files with 19 additions and 4 deletions

View File

@ -668,7 +668,7 @@ def Gather(rss, url, cache, options):
return rss return rss
def After(rss, options): def Before(rss, options):
for i, item in enumerate(list(rss.items)): for i, item in enumerate(list(rss.items)):
if options.smart and options.last: if options.smart and options.last:
if item.time < feeds.parse_time(options.last) and i > 2: if item.time < feeds.parse_time(options.last) and i > 2:
@ -688,6 +688,11 @@ def After(rss, options):
item.remove() item.remove()
continue continue
return rss
def After(rss, options):
for i, item in enumerate(list(rss.items)):
if item.desc and item.content: if item.desc and item.content:
if options.clip: if options.clip:
item.content = item.desc + "<br/><br/><center>* * *</center><br/><br/>" + item.content item.content = item.desc + "<br/><br/><center>* * *</center><br/><br/>" + item.content
@ -714,6 +719,10 @@ def After(rss, options):
if item.content: if item.content:
item.content = conv.handle(item.content) item.content = conv.handle(item.content)
return rss
def Format(rss, options):
if options.callback: if options.callback:
if re.match(r'^[a-zA-Z0-9\.]+$', options.callback) is not None: if re.match(r'^[a-zA-Z0-9\.]+$', options.callback) is not None:
return '%s(%s)' % (options.callback, rss.tojson()) return '%s(%s)' % (options.callback, rss.tojson())
@ -739,9 +748,11 @@ def process(url, cache=None, options=None):
options = Options(options) options = Options(options)
url, cache = Init(url, cache, options) url, cache = Init(url, cache, options)
rss = Fetch(url, cache, options) rss = Fetch(url, cache, options)
rss = Before(rss, options)
rss = Gather(rss, url, cache, 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): def cgi_app(environ, start_response):
@ -815,8 +826,10 @@ def cgi_app(environ, start_response):
start_response(headers['status'], headers.items()) start_response(headers['status'], headers.items())
rss = Before(rss, options)
rss = Gather(rss, url, cache, options) rss = Gather(rss, url, cache, options)
out = After(rss, options) rss = After(rss, options)
out = Format(rss, options)
if not options.silent: if not options.silent:
return out return out
@ -872,8 +885,10 @@ def cli_app():
url, cache = Init(url, os.path.expanduser('~/.cache/morss'), options) url, cache = Init(url, os.path.expanduser('~/.cache/morss'), options)
rss = Fetch(url, cache, options) rss = Fetch(url, cache, options)
rss = Before(rss, options)
rss = Gather(rss, url, cache, options) rss = Gather(rss, url, cache, options)
out = After(rss, options) rss = After(rss, options)
out = Format(rss, options)
if not options.silent: if not options.silent:
print out print out