Better content insertion

Also takes care of description, by creating one, when missing.
master
pictuga 2013-07-14 18:58:48 +02:00
parent 054f5c0846
commit 7275bb1a59
1 changed files with 18 additions and 2 deletions

View File

@ -81,6 +81,22 @@ def countWord(txt):
else: else:
return 0 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): def parseOptions(available):
options = None options = None
if 'REQUEST_URI' in os.environ: if 'REQUEST_URI' in os.environ:
@ -268,7 +284,7 @@ def Fill(item, cache, feedurl="/", fast=False):
log('old error') log('old error')
else: else:
log('cached') log('cached')
item.content = cache.get(item.link) setContent(item, cache.get(item.link))
return True return True
# super-fast mode # super-fast mode
@ -288,7 +304,7 @@ def Fill(item, cache, feedurl="/", fast=False):
out = readability.Document(data, url=url).summary(True) out = readability.Document(data, url=url).summary(True)
if countWord(out) > max(count_content, count_desc) > 0: if countWord(out) > max(count_content, count_desc) > 0:
item.content = out setContent(item, out)
cache.set(item.link, out) cache.set(item.link, out)
else: else:
log('not bigger enough') log('not bigger enough')