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 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
@ -2288,10 +2289,10 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str
postFilename=postFilename.name postFilename=postFilename.name
if not postFilename.endswith('.json'): if not postFilename.endswith('.json'):
continue continue
# extract the status number # Time of file creation
statusNumber=getStatusNumberFromPostFilename(postFilename) secondsSinceEpoch=getCreationTimeOfFile(postFilename)
if statusNumber: if secondsSinceEpoch:
postsInBoxDict[statusNumber]=os.path.join(boxDir, postFilename) postsInBoxDict[secondsSinceEpoch]=os.path.join(boxDir, postFilename)
postsCtr+=1 postsCtr+=1
noOfPosts=postsCtr noOfPosts=postsCtr
@ -2303,7 +2304,7 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str
# directory containing cached html posts # directory containing cached html posts
postCacheDir=boxDir.replace('/'+boxname,'/postcache') postCacheDir=boxDir.replace('/'+boxname,'/postcache')
for statusNumber,postFilename in postsInBox.items(): for secondsSinceEpoch,postFilename in postsInBox.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

View File

@ -431,3 +431,8 @@ 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