From 963f8226f8c3c174b2654e400ef762fcf0f66361 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 26 Feb 2020 10:26:04 +0000 Subject: [PATCH] Count posts without replies --- blog.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/blog.py b/blog.py index f58cb76bc..f99039e27 100644 --- a/blog.py +++ b/blog.py @@ -50,6 +50,13 @@ def noOfBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \ boxFound=True break if not boxFound: + # post may exist but has no replies + for postBox in tryPostBox: + postFilename= \ + baseDir+'/accounts/'+nickname+'@'+domain+'/'+postBox+'/'+ \ + postId.replace('/','#') + if os.path.isfile(postFilename): + return 1 return 0 replies=0 @@ -57,7 +64,7 @@ def noOfBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \ lines = f.readlines() for replyPostId in lines: replyPostId= \ - replyPostId.replace('\n','').replace('.json','') + replyPostId.replace('\n','').replace('.json','').replace('.replies','') replies+= \ 1 + \ noOfBlogReplies(baseDir,httpPrefix,translate, \ @@ -86,6 +93,19 @@ def getBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \ boxFound=True break if not boxFound: + # post may exist but has no replies + for postBox in tryPostBox: + postFilename= \ + baseDir+'/accounts/'+nickname+'@'+domain+'/'+postBox+'/'+ \ + postId.replace('/','#') + if os.path.isfile(postFilename): + postFilename= \ + baseDir+'/accounts/'+nickname+'@'+domain+ \ + '/postcache/'+ \ + postId.replace('/','#')+'.html' + if os.path.isfile(postFilename): + with open(postFilename, "r") as postFile: + return postFile.read()+'\n' return '' with open(postFilename, "r") as f: @@ -93,7 +113,7 @@ def getBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \ repliesStr='' for replyPostId in lines: replyPostId= \ - replyPostId.replace('\n','').replace('.json','') + replyPostId.replace('\n','').replace('.json','').replace('.replies','') postFilename= \ baseDir+'/accounts/'+nickname+'@'+domain+ \ '/postcache/'+ \