mirror of https://gitlab.com/bashrc2/epicyon
Tidying
parent
18942a2aba
commit
6ea5e0cf80
|
@ -1712,7 +1712,50 @@ def postContainsPublic(postJsonObject: {}) -> bool:
|
||||||
break
|
break
|
||||||
return containsPublic
|
return containsPublic
|
||||||
|
|
||||||
|
def loadIndividualPostAsHtmlFromCache(baseDir: str,nickname: str,domain: str, \
|
||||||
|
postJsonObject: {}) -> str:
|
||||||
|
"""If a cached html version of the given post exists then load it and
|
||||||
|
return the html text
|
||||||
|
"""
|
||||||
|
htmlPostCacheDir=baseDir+'/accounts/'+nickname+'@'+domain+'/postcache'
|
||||||
|
cachedPostFilename=htmlPostCacheDir+'/'+postJsonObject['id'].replace('/activity','').replace('/','#')+'.html'
|
||||||
|
postHtml=''
|
||||||
|
if not os.path.isfile(cachedPostFilename):
|
||||||
|
return postHtml
|
||||||
|
|
||||||
|
tries=0
|
||||||
|
while tries<3:
|
||||||
|
try:
|
||||||
|
with open(cachedPostFilename, 'r') as file:
|
||||||
|
postHtml = file.read()
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
# no sleep
|
||||||
|
tries+=1
|
||||||
|
if postHtml:
|
||||||
|
return postHtml
|
||||||
|
|
||||||
|
def saveIndividualPostAsHtmlToCache(baseDir: str,nickname: str,domain: str, \
|
||||||
|
postJsonObject: {},postHtml: str) -> bool:
|
||||||
|
"""Saves the given html for a post to a cache file
|
||||||
|
This is so that it can be quickly reloaded on subsequent refresh of the timeline
|
||||||
|
"""
|
||||||
|
htmlPostCacheDir=baseDir+'/accounts/'+nickname+'@'+domain+'/postcache'
|
||||||
|
cachedPostFilename=htmlPostCacheDir+'/'+postJsonObject['id'].replace('/activity','').replace('/','#')+'.html'
|
||||||
|
|
||||||
|
# create the cache directory if needed
|
||||||
|
if not os.path.isdir(htmlPostCacheDir):
|
||||||
|
os.mkdir(htmlPostCacheDir)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(cachedPostFilename, 'w') as fp:
|
||||||
|
fp.write(postHtml)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print('ERROR: saving post to cache '+str(e))
|
||||||
|
return False
|
||||||
|
|
||||||
def individualPostAsHtml(iconsDir: str,translate: {}, \
|
def individualPostAsHtml(iconsDir: str,translate: {}, \
|
||||||
pageNumber: int,baseDir: str, \
|
pageNumber: int,baseDir: str, \
|
||||||
session,wfRequest: {},personCache: {}, \
|
session,wfRequest: {},personCache: {}, \
|
||||||
|
@ -1730,23 +1773,11 @@ def individualPostAsHtml(iconsDir: str,translate: {}, \
|
||||||
""" Shows a single post as html
|
""" Shows a single post as html
|
||||||
"""
|
"""
|
||||||
if not showPublicOnly and storeToCache:
|
if not showPublicOnly and storeToCache:
|
||||||
# if a cached version of the post already exists then fetch it
|
postHtml= \
|
||||||
htmlPostCacheDir=baseDir+'/accounts/'+nickname+'@'+domain+'/postcache'
|
loadIndividualPostAsHtmlFromCache(baseDir,nickname,domain, \
|
||||||
cachedPostFilename=htmlPostCacheDir+'/'+postJsonObject['id'].replace('/activity','').replace('/','#')+'.html'
|
postJsonObject)
|
||||||
if os.path.isfile(cachedPostFilename):
|
if postHtml:
|
||||||
postStr=''
|
return postHtml
|
||||||
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
|
||||||
|
@ -2105,29 +2136,22 @@ def individualPostAsHtml(iconsDir: str,translate: {}, \
|
||||||
|
|
||||||
contentStr='<div class="message">'+contentStr+'</div>'
|
contentStr='<div class="message">'+contentStr+'</div>'
|
||||||
|
|
||||||
postStr=''
|
postHtml=''
|
||||||
if boxName!='tlmedia':
|
if boxName!='tlmedia':
|
||||||
postStr= \
|
postHtml= \
|
||||||
'<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:
|
||||||
postStr=galleryStr
|
postHtml=galleryStr
|
||||||
|
|
||||||
if not showPublicOnly and storeToCache:
|
if not showPublicOnly and storeToCache:
|
||||||
# save to posts cache on file
|
saveIndividualPostAsHtmlToCache(baseDir,nickname,domain, \
|
||||||
if not os.path.isdir(htmlPostCacheDir):
|
postJsonObject,postHtml)
|
||||||
os.mkdir(htmlPostCacheDir)
|
|
||||||
|
|
||||||
try:
|
return postHtml
|
||||||
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