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.master
parent
208d70d3db
commit
edff54a016
9
feeds.py
9
feeds.py
|
@ -343,6 +343,15 @@ class FeedItem(FeedBase):
|
||||||
description = desc = FeedDescriptor('desc')
|
description = desc = FeedDescriptor('desc')
|
||||||
content = FeedDescriptor('content')
|
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 + "<br/><br/>* * *<br/><br/>" + value
|
||||||
|
else:
|
||||||
|
self.content = value
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
self.xml.getparent().remove(self.xml)
|
self.xml.getparent().remove(self.xml)
|
||||||
|
|
||||||
|
|
22
morss.py
22
morss.py
|
@ -61,22 +61,6 @@ 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():
|
def parseOptions():
|
||||||
url = ''
|
url = ''
|
||||||
options = []
|
options = []
|
||||||
|
@ -264,7 +248,7 @@ def decodeHTML(data, con=None):
|
||||||
log(enc)
|
log(enc)
|
||||||
return data.decode(enc, 'replace')
|
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 """
|
""" Returns True when it has done its best """
|
||||||
|
|
||||||
if not item.link:
|
if not item.link:
|
||||||
|
@ -328,7 +312,7 @@ def Fill(item, cache, feedurl='/', fast=False):
|
||||||
log('old error')
|
log('old error')
|
||||||
else:
|
else:
|
||||||
log('cached')
|
log('cached')
|
||||||
setContent(item, cache.get(link))
|
item.pushContent(cache.get(link), clip)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# super-fast mode
|
# super-fast mode
|
||||||
|
@ -354,7 +338,7 @@ def Fill(item, cache, feedurl='/', fast=False):
|
||||||
out = readability.Document(data, url=con.url).summary(True)
|
out = readability.Document(data, url=con.url).summary(True)
|
||||||
|
|
||||||
if countWord(out) > max(count_content, count_desc) > 0:
|
if countWord(out) > max(count_content, count_desc) > 0:
|
||||||
setContent(item, out)
|
item.pushContent(out, clip)
|
||||||
cache.set(link, out)
|
cache.set(link, out)
|
||||||
else:
|
else:
|
||||||
log('not bigger enough')
|
log('not bigger enough')
|
||||||
|
|
Loading…
Reference in New Issue