Archive based on creation date of post files

main2
Bob Mottram 2019-11-06 13:35:25 +00:00
parent 693c64b4f3
commit b2f926eaa3
2 changed files with 11 additions and 5 deletions

View File

@ -41,6 +41,7 @@ from utils import validNickname
from utils import locatePost
from utils import loadJson
from utils import saveJson
from utils import getCreationTimeOfFile
from capabilities import getOcapFilename
from capabilities import capabilitiesUpdate
from media import attachMedia
@ -2288,10 +2289,10 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str
postFilename=postFilename.name
if not postFilename.endswith('.json'):
continue
# extract the status number
statusNumber=getStatusNumberFromPostFilename(postFilename)
if statusNumber:
postsInBoxDict[statusNumber]=os.path.join(boxDir, postFilename)
# Time of file creation
secondsSinceEpoch=getCreationTimeOfFile(postFilename)
if secondsSinceEpoch:
postsInBoxDict[secondsSinceEpoch]=os.path.join(boxDir, postFilename)
postsCtr+=1
noOfPosts=postsCtr
@ -2303,7 +2304,7 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str
# directory containing cached html posts
postCacheDir=boxDir.replace('/'+boxname,'/postcache')
for statusNumber,postFilename in postsInBox.items():
for secondsSinceEpoch,postFilename in postsInBox.items():
filePath = os.path.join(boxDir, postFilename)
if not os.path.isfile(filePath):
continue

View File

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