forked from indymedia/epicyon
Recursive blog replies
parent
d30a46bcc9
commit
90e45cd6ef
51
blog.py
51
blog.py
|
@ -31,47 +31,72 @@ from posts import createBlogsTimeline
|
||||||
|
|
||||||
def noOfBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
def noOfBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
||||||
nickname: str,domain: str,domainFull: str, \
|
nickname: str,domain: str,domainFull: str, \
|
||||||
postJsonObject: {}) -> int:
|
postId: str,depth=0) -> int:
|
||||||
"""Returns the number of replies on the post
|
"""Returns the number of replies on the post
|
||||||
|
This is recursive, so can handle replies to replies
|
||||||
"""
|
"""
|
||||||
if not postJsonObject['object'].get('id'):
|
if depth>4:
|
||||||
|
return 0
|
||||||
|
if not postId:
|
||||||
return 0
|
return 0
|
||||||
postFilename= \
|
postFilename= \
|
||||||
baseDir+'/accounts/'+nickname+'@'+domain+'/tlblogs/'+ \
|
baseDir+'/accounts/'+nickname+'@'+domain+'/tlblogs/'+ \
|
||||||
postJsonObject['object']['id'].replace('/','#')+'.replies'
|
postId.replace('/','#')+'.replies'
|
||||||
if not os.path.isfile(postFilename):
|
if not os.path.isfile(postFilename):
|
||||||
return 0
|
return 0
|
||||||
|
replies=0
|
||||||
with open(postFilename, "r") as f:
|
with open(postFilename, "r") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
return len(lines)
|
for replyPostId in lines:
|
||||||
return 0
|
replyPostId= \
|
||||||
|
replyPostId.replace('\n','').replace('.json','')
|
||||||
|
replies+= \
|
||||||
|
1 + \
|
||||||
|
noOfBlogReplies(baseDir,httpPrefix,translate, \
|
||||||
|
nickname,domain,domainFull, \
|
||||||
|
replyPostId,depth+1)
|
||||||
|
return replies
|
||||||
|
|
||||||
|
|
||||||
def getBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
def getBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
||||||
nickname: str,domain: str,domainFull: str, \
|
nickname: str,domain: str,domainFull: str, \
|
||||||
postJsonObject: {}) -> str:
|
postId: str,depth=0) -> str:
|
||||||
"""Returns the number of replies on the post
|
"""Returns the number of replies on the post
|
||||||
"""
|
"""
|
||||||
if not postJsonObject['object'].get('id'):
|
if depth>4:
|
||||||
|
return ''
|
||||||
|
if not postId:
|
||||||
return ''
|
return ''
|
||||||
postFilename= \
|
postFilename= \
|
||||||
baseDir+'/accounts/'+nickname+'@'+domain+'/tlblogs/'+ \
|
baseDir+'/accounts/'+nickname+'@'+domain+'/tlblogs/'+ \
|
||||||
postJsonObject['object']['id'].replace('/','#')+'.replies'
|
postId.replace('/','#')+'.replies'
|
||||||
if not os.path.isfile(postFilename):
|
if not os.path.isfile(postFilename):
|
||||||
return ''
|
return ''
|
||||||
with open(postFilename, "r") as f:
|
with open(postFilename, "r") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
repliesStr=''
|
repliesStr=''
|
||||||
for messageId in lines:
|
for messageId in lines:
|
||||||
|
replyPostId= \
|
||||||
|
replyPostId.replace('\n','').replace('.json','')
|
||||||
postFilename= \
|
postFilename= \
|
||||||
baseDir+'/accounts/'+nickname+'@'+domain+ \
|
baseDir+'/accounts/'+nickname+'@'+domain+ \
|
||||||
'/postcache/'+ \
|
'/postcache/'+ \
|
||||||
messageId.replace('\n','').replace('/','#')+'.html'
|
replyPostId.replace('\n','').replace('/','#')+'.html'
|
||||||
if not os.path.isfile(postFilename):
|
if not os.path.isfile(postFilename):
|
||||||
continue
|
continue
|
||||||
with open(postFilename, "r") as postFile:
|
with open(postFilename, "r") as postFile:
|
||||||
repliesStr+=postFile.read()+'\n'
|
repliesStr+=postFile.read()+'\n'
|
||||||
return repliesStr.replace(translate['SHOW MORE'],'-').replace('?tl=outbox','?tl=tlblogs')
|
repliesStr+= \
|
||||||
|
getBlogReplies(baseDir,httpPrefix,translate, \
|
||||||
|
nickname,domain,domainFull, \
|
||||||
|
replyPostId,depth+1)
|
||||||
|
|
||||||
|
# indicate the reply indentation level
|
||||||
|
indentStr='>'
|
||||||
|
for indentLevel in range(depth):
|
||||||
|
indentStr+=' >'
|
||||||
|
|
||||||
|
return repliesStr.replace(translate['SHOW MORE'],indentStr).replace('?tl=outbox','?tl=tlblogs')
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,7 +188,7 @@ def htmlBlogPostContent(authorized: bool, \
|
||||||
replies= \
|
replies= \
|
||||||
noOfBlogReplies(baseDir,httpPrefix,translate, \
|
noOfBlogReplies(baseDir,httpPrefix,translate, \
|
||||||
nickname,domain,domainFull, \
|
nickname,domain,domainFull, \
|
||||||
postJsonObject)
|
postJsonObject['object']['id'])
|
||||||
if replies>0:
|
if replies>0:
|
||||||
if not authorized:
|
if not authorized:
|
||||||
blogStr+= \
|
blogStr+= \
|
||||||
|
@ -176,12 +201,12 @@ def htmlBlogPostContent(authorized: bool, \
|
||||||
blogStr+= \
|
blogStr+= \
|
||||||
getBlogReplies(baseDir,httpPrefix,translate, \
|
getBlogReplies(baseDir,httpPrefix,translate, \
|
||||||
nickname,domain,domainFull, \
|
nickname,domain,domainFull, \
|
||||||
postJsonObject)
|
postJsonObject['object']['id'])
|
||||||
else:
|
else:
|
||||||
blogStr+= \
|
blogStr+= \
|
||||||
getBlogReplies(baseDir,httpPrefix,translate, \
|
getBlogReplies(baseDir,httpPrefix,translate, \
|
||||||
nickname,domain,domainFull, \
|
nickname,domain,domainFull, \
|
||||||
postJsonObject).replace('>'+titleStr+'<','')
|
postJsonObject['object']['id']).replace('>'+titleStr+'<','')
|
||||||
blogStr+='<br><hr>\n'
|
blogStr+='<br><hr>\n'
|
||||||
return blogStr
|
return blogStr
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue