diff --git a/newswire.py b/newswire.py index 3f76e471b..81927fa7a 100644 --- a/newswire.py +++ b/newswire.py @@ -82,7 +82,7 @@ def getNewswireTags(text: str, maxTags: int) -> []: def addNewswireDictEntry(baseDir: str, domain: str, newswire: {}, dateStr: str, - title: str, link: str, + title: str, content: str, link: str, votesStatus: str, postFilename: str, description: str, moderated: bool, mirrored: bool, @@ -412,6 +412,7 @@ def isNewswireBlogPost(postJsonObject: {}) -> bool: return False if postJsonObject['object'].get('summary') and \ postJsonObject['object'].get('url') and \ + postJsonObject['object'].get('content') and \ postJsonObject['object'].get('published'): return isPublicPost(postJsonObject) return False @@ -443,6 +444,19 @@ 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, @@ -500,7 +514,7 @@ def addAccountBlogsToNewswire(baseDir: str, nickname: str, domain: str, votes = [] if os.path.isfile(fullPostFilename + '.votes'): votes = loadJson(fullPostFilename + '.votes') - description = '' + description = firstParagraph(postJsonObject) addNewswireDictEntry(baseDir, domain, newswire, published, postJsonObject['object']['summary'],