From 30e63970f63ef4b84ff3ac558f20d9333adb1980 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 8 Nov 2020 10:45:33 +0000 Subject: [PATCH] Include description in newswire rss feed --- blog.py | 8 +++++--- newswire.py | 7 +++++-- utils.py | 3 +-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/blog.py b/blog.py index 606fc923f..96d52a1fc 100644 --- a/blog.py +++ b/blog.py @@ -19,7 +19,7 @@ from utils import getNicknameFromActor from utils import getDomainFromActor from utils import locatePost from utils import loadJson -from utils import firstParagraph +from utils import firstParagraphFromString from posts import createBlogsTimeline from newswire import rss2Header from newswire import rss2Footer @@ -313,7 +313,8 @@ 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) + content = postJsonObject['object']['content'] + description = firstParagraphFromString(content) rssStr = ' ' rssStr += ' ' + titleStr + '' rssStr += ' ' + messageLink + '' @@ -343,7 +344,8 @@ 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) + content = postJsonObject['object']['content'] + description = firstParagraphFromString(content) rssStr = 'title: ' + titleStr + '\n' rssStr += 'link: ' + messageLink + '\n' rssStr += 'description: ' + description + '\n' diff --git a/newswire.py b/newswire.py index e738fef4e..4fca15a78 100644 --- a/newswire.py +++ b/newswire.py @@ -12,7 +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 firstParagraphFromString from utils import isPublicPost from utils import locatePost from utils import loadJson @@ -387,6 +387,8 @@ def getRSSfromDict(baseDir: str, newswire: {}, continue rssStr += '\n' rssStr += ' ' + fields[0] + '\n' + description = firstParagraphFromString(fields[4]) + rssStr += ' ' + description + '\n' url = fields[1] if domainFull not in url: url = httpPrefix + '://' + domainFull + url @@ -502,7 +504,8 @@ def addAccountBlogsToNewswire(baseDir: str, nickname: str, domain: str, votes = [] if os.path.isfile(fullPostFilename + '.votes'): votes = loadJson(fullPostFilename + '.votes') - description = firstParagraph(postJsonObject) + content = postJsonObject['object']['content'] + description = firstParagraphFromString(content) addNewswireDictEntry(baseDir, domain, newswire, published, postJsonObject['object']['summary'], diff --git a/utils.py b/utils.py index 6640e1dde..11d00aa03 100644 --- a/utils.py +++ b/utils.py @@ -19,11 +19,10 @@ from calendar import monthrange from followingCalendar import addPersonToCalendar -def firstParagraph(postJsonObject: {}) -> str: +def firstParagraphFromString(content: str) -> str: """Get the first paragraph from a blog post to be used as a summary in the newswire feed """ - content = postJsonObject['object']['content'] if '

' not in content or '

' not in content: return removeHtml(content) paragraph = content.split('

')[1]