Removing tag from file

main
Bob Mottram 2019-12-12 19:02:06 +00:00
parent a19e61c90d
commit 7b96e12e2b
1 changed files with 13 additions and 8 deletions

View File

@ -361,16 +361,21 @@ def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilena
if not os.path.isfile(tagIndexFilename): if not os.path.isfile(tagIndexFilename):
continue continue
# remove postId from the tag index file # remove postId from the tag index file
lines=None
with open(tagIndexFilename, "r") as f: with open(tagIndexFilename, "r") as f:
lines=f.readlines() lines=f.readlines()
newlines=lines.replace(postId+'\n','') if lines:
if newlines!=lines: newlines=''
if not newlines.strip(): for l in lines:
# if there are no lines then remove the hashtag file if postId in l:
os.remove(tagIndexFilename) continue
else: newlines+=l
with open(tagIndexFilename, "w+") as f: if not newlines.strip():
f.write(newlines) # 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 # remove any replies
repliesFilename=postFilename.replace('.json','.replies') repliesFilename=postFilename.replace('.json','.replies')