Include description within rss feeds

merge-requests/8/head
Bob Mottram 2020-11-08 10:30:25 +00:00
parent bb936c455a
commit 49414c7012
3 changed files with 20 additions and 13 deletions

View File

@ -19,6 +19,7 @@ from utils import getNicknameFromActor
from utils import getDomainFromActor
from utils import locatePost
from utils import loadJson
from utils import firstParagraph
from posts import createBlogsTimeline
from newswire import rss2Header
from newswire import rss2Footer
@ -312,9 +313,12 @@ def htmlBlogPostRSS2(authorized: bool,
pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")
titleStr = postJsonObject['object']['summary']
rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")
description = firstParagraph(postJsonObject)
rssStr = ' <item>'
rssStr += ' <title>' + titleStr + '</title>'
rssStr += ' <link>' + messageLink + '</link>'
rssStr += \
' <description>' + description + '</description>'
rssStr += ' <pubDate>' + rssDateStr + '</pubDate>'
rssStr += ' </item>'
return rssStr
@ -339,8 +343,10 @@ def htmlBlogPostRSS3(authorized: bool,
pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")
titleStr = postJsonObject['object']['summary']
rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")
description = firstParagraph(postJsonObject)
rssStr = 'title: ' + titleStr + '\n'
rssStr += 'link: ' + messageLink + '\n'
rssStr += 'description: ' + description + '\n'
rssStr += 'created: ' + rssDateStr + '\n\n'
return rssStr

View File

@ -12,6 +12,7 @@ from socket import error as SocketError
import errno
from datetime import datetime
from collections import OrderedDict
from utils import firstParagraph
from utils import isPublicPost
from utils import locatePost
from utils import loadJson
@ -444,19 +445,6 @@ def getHashtagsFromPost(postJsonObject: {}) -> []:
return tags
def firstParagraph(postJsonObject: {}) -> str:
"""Get the first paragraph from a blog post
to be used as a summary in the newswire feed
"""
content = postJsonObject['object']['content']
if '<p>' not in content or '</p>' not in content:
return removeHtml(content)
paragraph = content.split('<p>')[1]
if '</p>' in paragraph:
paragraph = paragraph.split('</p>')[0]
return removeHtml(paragraph)
def addAccountBlogsToNewswire(baseDir: str, nickname: str, domain: str,
newswire: {},
maxBlogsPerAccount: int,

View File

@ -19,6 +19,19 @@ from calendar import monthrange
from followingCalendar import addPersonToCalendar
def firstParagraph(postJsonObject: {}) -> str:
"""Get the first paragraph from a blog post
to be used as a summary in the newswire feed
"""
content = postJsonObject['object']['content']
if '<p>' not in content or '</p>' not in content:
return removeHtml(content)
paragraph = content.split('<p>')[1]
if '</p>' in paragraph:
paragraph = paragraph.split('</p>')[0]
return removeHtml(paragraph)
def removeHtml(content: str) -> str:
"""Removes html links from the given content.
Used to ensure that profile descriptions don't contain dubious content