From 0710f3d38a8d910be0e593969112b1de09f5e3e4 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 14 Sep 2019 12:18:34 +0100 Subject: [PATCH] Improve archiving by extracting status code --- posts.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/posts.py b/posts.py index c7afc7364..179caf987 100644 --- a/posts.py +++ b/posts.py @@ -1910,10 +1910,27 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str if not os.path.isdir(archiveDir): os.mkdir(archiveDir) boxDir = createPersonDir(nickname,domain,baseDir,boxname) - postsInBox=sorted(os.listdir(boxDir), reverse=False) + postsInBox=os.listdir(boxDir) noOfPosts=len(postsInBox) if noOfPosts<=maxPostsInBox: return + + postsInBoxDict={} + postsCtr=0 + for postFilename in postsInBox: + if not postFilename.endswith('.json'): + continue + # extract the status number + statusNumber=getStatusNumberFromPostFilename(postFilename) + if statusNumber: + postsInBoxDict[statusNumber]=os.path.join(boxDir, postFilename) + postsCtr+=1 + + noOfPosts=postsCtr + if noOfPosts<=maxPostsInBox: + return + # sort the list in ascending order of date + postsInBox=OrderedDict(sorted(postsInBoxDict.items(),reverse=False)) for postFilename in postsInBox: filePath = os.path.join(boxDir, postFilename)