forked from indymedia/epicyon
Create posts cache
parent
ed067498da
commit
6b9069a35f
|
@ -1728,6 +1728,24 @@ def individualPostAsHtml(iconsDir: str,translate: {}, \
|
||||||
showPublicOnly=False) -> str:
|
showPublicOnly=False) -> str:
|
||||||
""" Shows a single post as html
|
""" Shows a single post as html
|
||||||
"""
|
"""
|
||||||
|
# if a cached version of the post already exists then fetch it
|
||||||
|
htmlPostCacheDir=baseDir+'/accounts/'+nickname+'@'+domain+'/postcache'
|
||||||
|
cachedPostFilename=htmlPostCacheDir+'/'+postJsonObject['id'].replace('/','#')+'.html'
|
||||||
|
if os.path.isfile(cachedPostFilename):
|
||||||
|
postStr=''
|
||||||
|
tries=0
|
||||||
|
while tries<3:
|
||||||
|
try:
|
||||||
|
with open(cachedPostFilename, 'r') as file:
|
||||||
|
postStr = file.read()
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
# no sleep
|
||||||
|
tries+=1
|
||||||
|
if postStr:
|
||||||
|
return postStr
|
||||||
|
|
||||||
# If this is the inbox timeline then don't show the repeat icon on any DMs
|
# If this is the inbox timeline then don't show the repeat icon on any DMs
|
||||||
showRepeatIcon=showRepeats
|
showRepeatIcon=showRepeats
|
||||||
showDMicon=False
|
showDMicon=False
|
||||||
|
@ -2085,15 +2103,27 @@ def individualPostAsHtml(iconsDir: str,translate: {}, \
|
||||||
|
|
||||||
contentStr='<div class="message">'+contentStr+'</div>'
|
contentStr='<div class="message">'+contentStr+'</div>'
|
||||||
|
|
||||||
|
postStr=''
|
||||||
if boxName!='tlmedia':
|
if boxName!='tlmedia':
|
||||||
return \
|
postStr= \
|
||||||
'<div class="'+containerClass+'">\n'+ \
|
'<div class="'+containerClass+'">\n'+ \
|
||||||
avatarImageInPost+ \
|
avatarImageInPost+ \
|
||||||
'<p class="post-title">'+titleStr+replyAvatarImageInPost+'</p>'+ \
|
'<p class="post-title">'+titleStr+replyAvatarImageInPost+'</p>'+ \
|
||||||
contentStr+footerStr+ \
|
contentStr+footerStr+ \
|
||||||
'</div>\n'
|
'</div>\n'
|
||||||
else:
|
else:
|
||||||
return galleryStr
|
postStr=galleryStr
|
||||||
|
|
||||||
|
# save to posts cache on file
|
||||||
|
if not os.path.isdir(htmlPostCacheDir):
|
||||||
|
os.mkdir(htmlPostCacheDir)
|
||||||
|
try:
|
||||||
|
with open(cachedPostFilename, 'w') as fp:
|
||||||
|
fp.write(postStr)
|
||||||
|
except Exception as e:
|
||||||
|
print('ERROR: saving post to cache '+str(e))
|
||||||
|
|
||||||
|
return postStr
|
||||||
|
|
||||||
def isQuestion(postObjectJson: {}) -> bool:
|
def isQuestion(postObjectJson: {}) -> bool:
|
||||||
""" is the given post a question?
|
""" is the given post a question?
|
||||||
|
|
Loading…
Reference in New Issue