From 1a94e9b239e290991a32379bb59f73eb61bdd2a4 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 12 Dec 2019 12:54:39 +0000 Subject: [PATCH] Handling removal of hashtags --- utils.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/utils.py b/utils.py index 6bb11075f..6c059ca76 100644 --- a/utils.py +++ b/utils.py @@ -360,11 +360,15 @@ def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilena continue # remove postId from the tag index file with open(tagIndexFilename, "r") as f: - lines = f.readlines() - with open(tagIndexFilename, "w+") as f: - for line in lines: - if line.strip("\n") != postId: - f.write(line) + lines=f.readlines() + newlines=lines.replace(postId+'\n','') + if newlines!=lines: + if not newlines.strip(): + # if there are no lines then remove the hashtag file + os.remove(tagIndexFilename) + else: + with open(tagIndexFilename, "w+") as f: + f.write(newlines) # remove any replies repliesFilename=postFilename.replace('.json','.replies')