From fed40ed916785db6ef89cbe064becb2aa4b53fc4 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 25 Feb 2020 20:53:02 +0000 Subject: [PATCH] Show replies on blog post --- blog.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/blog.py b/blog.py index b62533d7..5e54a74f 100644 --- a/blog.py +++ b/blog.py @@ -46,6 +46,34 @@ def noOfBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \ return 0 +def getBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \ + nickname: str,domain: str,domainFull: str, \ + postJsonObject: {}) -> str: + """Returns the number of replies on the post + """ + if not postJsonObject['object'].get('id'): + return '' + postFilename= \ + baseDir+'/accounts/'+nickname+'@'+domain+'/tlblogs/'+ \ + postJsonObject['object']['id'].replace('/','#')+'.replies' + if not os.path.isfile(postFilename): + return '' + with open(postFilename, "r") as f: + lines = f.readlines() + repliesStr='' + for messageId in lines: + postFilename= \ + baseDir+'/accounts/'+nickname+'@'+domain+ \ + '/postcache/'+ \ + messageId.replace('\n','').replace('/','#')+'.html' + if not os.path.isfile(postFilename): + continue + with open(postFilename, "r") as postFile: + repliesStr+=postFile.read() + return repliesStr + return '' + + def htmlBlogPostContent(authorized: bool, \ baseDir: str,httpPrefix: str,translate: {}, \ nickname: str,domain: str,domainFull: str, \ @@ -133,6 +161,12 @@ def htmlBlogPostContent(authorized: bool, \ blogStr+= \ '

'+ \ translate['Replies'].lower()+': '+str(replies)+'

' + else: + blogStr+= \ + getBlogReplies(baseDir,httpPrefix,translate, \ + nickname,domain,domainFull, \ + postJsonObject) + blogStr+='

\n' if not linkedAuthor: blogStr+= \