From 49414c70128629c62db4d4d07e83d07b7a146aae Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Sun, 8 Nov 2020 10:30:25 +0000
Subject: [PATCH] Include description within rss feeds
---
blog.py | 6 ++++++
newswire.py | 14 +-------------
utils.py | 13 +++++++++++++
3 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/blog.py b/blog.py
index 4c3e83c70..606fc923f 100644
--- a/blog.py
+++ b/blog.py
@@ -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 = ' '
rssStr += ' ' + titleStr + ''
rssStr += ' ' + messageLink + ''
+ rssStr += \
+ ' ' + description + ''
rssStr += ' ' + rssDateStr + ''
rssStr += ' '
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
diff --git a/newswire.py b/newswire.py
index f69d5350d..e738fef4e 100644
--- a/newswire.py
+++ b/newswire.py
@@ -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 '
' not in content or '
' not in content:
- return removeHtml(content)
- paragraph = content.split('
')[1]
- if '
' in paragraph:
- paragraph = paragraph.split('
')[0]
- return removeHtml(paragraph)
-
-
def addAccountBlogsToNewswire(baseDir: str, nickname: str, domain: str,
newswire: {},
maxBlogsPerAccount: int,
diff --git a/utils.py b/utils.py
index 08d21f159..6640e1dde 100644
--- a/utils.py
+++ b/utils.py
@@ -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 '
' not in content or '
' not in content:
+ return removeHtml(content)
+ paragraph = content.split('
')[1]
+ if '
' in paragraph:
+ paragraph = paragraph.split('')[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