From 7275bb1a599658df86053251acd797ec7fdb25ba Mon Sep 17 00:00:00 2001 From: pictuga Date: Sun, 14 Jul 2013 18:58:48 +0200 Subject: [PATCH] Better content insertion Also takes care of description, by creating one, when missing. --- morss.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/morss.py b/morss.py index 7fd113a..8d8f105 100644 --- a/morss.py +++ b/morss.py @@ -81,6 +81,22 @@ def countWord(txt): else: return 0 +def makeDesc(txt, length, suffix='...'): + ' '.join(txt.split()[:length]) + suffix + +def setContent(item, txt): + if not item.desc: + if item.content: + log('content alone') + item.desc = item.content + item.content = txt + else: + log('empty') + item.desc = makeDesc(txt, 30) + item.content = txt + else: + item.content = txt + def parseOptions(available): options = None if 'REQUEST_URI' in os.environ: @@ -268,7 +284,7 @@ def Fill(item, cache, feedurl="/", fast=False): log('old error') else: log('cached') - item.content = cache.get(item.link) + setContent(item, cache.get(item.link)) return True # super-fast mode @@ -288,7 +304,7 @@ def Fill(item, cache, feedurl="/", fast=False): out = readability.Document(data, url=url).summary(True) if countWord(out) > max(count_content, count_desc) > 0: - item.content = out + setContent(item, out) cache.set(item.link, out) else: log('not bigger enough')