Get published time

main2
Bob Mottram 2019-11-06 14:50:17 +00:00
parent a24959fa66
commit 74a0b0b2c1
2 changed files with 20 additions and 17 deletions

View File

@ -41,7 +41,6 @@ from utils import validNickname
from utils import locatePost from utils import locatePost
from utils import loadJson from utils import loadJson
from utils import saveJson from utils import saveJson
from utils import getCreationTimeOfFile
from capabilities import getOcapFilename from capabilities import getOcapFilename
from capabilities import capabilitiesUpdate from capabilities import capabilitiesUpdate
from media import attachMedia from media import attachMedia
@ -2291,27 +2290,36 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str
if not postFilename.endswith('.json'): if not postFilename.endswith('.json'):
continue continue
# Time of file creation # Time of file creation
secondsSinceEpoch=getCreationTimeOfFile(os.path.join(boxDir, postFilename)) fullFilename=os.path.join(boxDir,postFilename)
if secondsSinceEpoch: if os.path.isfile(fullFilename):
postsInBoxDict[secondsSinceEpoch]=postFilename content=open(fullFilename).read()
postsCtr+=1 if '"published":' in content:
publishedStr=content.split('"published":')[1]
if '"' in publishedStr:
publishedStr=publishedStr.split('"')[1]
print('publishedStr: '+publishedStr)
postsInBoxDict[secondsSinceEpoch]=postFilename
postsCtr+=1
return
noOfPosts=postsCtr noOfPosts=postsCtr
if noOfPosts<=maxPostsInBox: if noOfPosts<=maxPostsInBox:
return return
# sort the list in ascending order of date # sort the list in ascending order of date
postsInBox=OrderedDict(sorted(postsInBoxDict.items(),reverse=False)) postsInBoxSorted=OrderedDict(sorted(postsInBoxDict.items(),reverse=False))
# directory containing cached html posts # directory containing cached html posts
postCacheDir=boxDir.replace('/'+boxname,'/postcache') postCacheDir=boxDir.replace('/'+boxname,'/postcache')
for secondsSinceEpoch,postFilename in postsInBox.items(): for secondsSinceEpoch,postFilename in postsInBoxSorted.items():
filePath = os.path.join(boxDir, postFilename) filePath=os.path.join(boxDir,postFilename)
if not os.path.isfile(filePath): if not os.path.isfile(filePath):
continue continue
if archiveDir: if archiveDir:
repliesPath=filePath.replace('.json','.replies') repliesPath=filePath.replace('.json','.replies')
archivePath = os.path.join(archiveDir, postFilename) archivePath=os.path.join(archiveDir,postFilename)
os.rename(filePath,archivePath) os.rename(filePath,archivePath)
if os.path.isfile(repliesPath): if os.path.isfile(repliesPath):
os.rename(repliesPath,archivePath) os.rename(repliesPath,archivePath)
@ -2319,12 +2327,12 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str
deletePost(baseDir,httpPrefix,nickname,domain,filePath,False) deletePost(baseDir,httpPrefix,nickname,domain,filePath,False)
# remove cached html posts # remove cached html posts
postCacheFilename=os.path.join(postCacheDir, postFilename).replace('.json','.html') postCacheFilename=os.path.join(postCacheDir,postFilename).replace('.json','.html')
if os.path.isfile(postCacheFilename): if os.path.isfile(postCacheFilename):
os.remove(postCacheFilename) os.remove(postCacheFilename)
noOfPosts -= 1 noOfPosts-=1
if noOfPosts <= maxPostsInBox: if noOfPosts<=maxPostsInBox:
break break
def getPublicPostsOfPerson(baseDir: str,nickname: str,domain: str, \ def getPublicPostsOfPerson(baseDir: str,nickname: str,domain: str, \

View File

@ -431,8 +431,3 @@ def getCachedPostFilename(baseDir: str,nickname: str,domain: str, \
getCachedPostDirectory(baseDir,nickname,domain)+ \ getCachedPostDirectory(baseDir,nickname,domain)+ \
'/'+postJsonObject['id'].replace('/activity','').replace('/','#')+'.html' '/'+postJsonObject['id'].replace('/activity','').replace('/','#')+'.html'
return cachedPostFilename return cachedPostFilename
def getCreationTimeOfFile(filename: str):
"""Gets the time of creation of a file in seconds since epoch
"""
return os.stat(filename).st_ctime