From edff54a016e88e11a52bbe7940e5a17530300227 Mon Sep 17 00:00:00 2001 From: pictuga Date: Wed, 25 Sep 2013 12:18:22 +0200 Subject: [PATCH] Add pushContent in feeds.py Useful for twitter (later) for it's "clip" toggle, which keeps the original desc/content above the article. Makes changing the content, while keeping the original stub in place, easier. --- feeds.py | 9 +++++++++ morss.py | 22 +++------------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/feeds.py b/feeds.py index 2ee5d51..5c34b85 100644 --- a/feeds.py +++ b/feeds.py @@ -343,6 +343,15 @@ class FeedItem(FeedBase): description = desc = FeedDescriptor('desc') content = FeedDescriptor('content') + def pushContent(self, value, clip=False): + if not self.desc and self.content: + self.desc = self.content + + if self.desc and clip: + self.content = self.desc + "

* * *

" + value + else: + self.content = value + def remove(self): self.xml.getparent().remove(self.xml) diff --git a/morss.py b/morss.py index 952559b..c67cf6a 100644 --- a/morss.py +++ b/morss.py @@ -61,22 +61,6 @@ 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(): url = '' options = [] @@ -264,7 +248,7 @@ def decodeHTML(data, con=None): log(enc) return data.decode(enc, 'replace') -def Fill(item, cache, feedurl='/', fast=False): +def Fill(item, cache, feedurl='/', fast=False, clip=False): """ Returns True when it has done its best """ if not item.link: @@ -328,7 +312,7 @@ def Fill(item, cache, feedurl='/', fast=False): log('old error') else: log('cached') - setContent(item, cache.get(link)) + item.pushContent(cache.get(link), clip) return True # super-fast mode @@ -354,7 +338,7 @@ def Fill(item, cache, feedurl='/', fast=False): out = readability.Document(data, url=con.url).summary(True) if countWord(out) > max(count_content, count_desc) > 0: - setContent(item, out) + item.pushContent(out, clip) cache.set(link, out) else: log('not bigger enough')