From 949f52ae9b64ffa0a743cad771c99ebb88b3c811 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 21 May 2020 23:12:31 +0100 Subject: [PATCH] Remove bookmark from index first --- bookmarks.py | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/bookmarks.py b/bookmarks.py index dfc5ae18..b4ca12dd 100644 --- a/bookmarks.py +++ b/bookmarks.py @@ -42,6 +42,28 @@ def undoBookmarksCollectionEntry(recentPostsCache: {}, os.remove(cachedPostFilename) removePostFromCache(postJsonObject, recentPostsCache) + # remove from the index + bookmarksIndexFilename = baseDir + '/accounts/' + \ + nickname + '@' + domain + '/bookmarks.index' + if not os.path.isfile(bookmarksIndexFilename): + return + if '/' in postFilename: + bookmarkIndex = postFilename.split('/')[-1].strip() + else: + bookmarkIndex = postFilename.strip() + if bookmarkIndex not in open(bookmarksIndexFilename).read(): + return + indexStr = '' + indexStrChanged = False + with open(bookmarksIndexFilename, 'r') as indexFile: + indexStr = indexFile.read().replace(bookmarkIndex + '\n', '') + indexStrChanged = True + if indexStrChanged: + bookmarksIndexFile = open(bookmarksIndexFilename, 'w') + if bookmarksIndexFile: + bookmarksIndexFile.write(indexStr) + bookmarksIndexFile.close() + if not postJsonObject.get('type'): return if postJsonObject['type'] != 'Create': @@ -85,28 +107,6 @@ def undoBookmarksCollectionEntry(recentPostsCache: {}, postJsonObject['object']['bookmarks']['totalItems'] = bmItLen saveJson(postJsonObject, postFilename) - # remove from the index - bookmarksIndexFilename = baseDir + '/accounts/' + \ - nickname + '@' + domain + '/bookmarks.index' - if not os.path.isfile(bookmarksIndexFilename): - return - if '/' in postFilename: - bookmarkIndex = postFilename.split('/')[-1].strip() - else: - bookmarkIndex = postFilename.strip() - if bookmarkIndex not in open(bookmarksIndexFilename).read(): - return - indexStr = '' - indexStrChanged = False - with open(bookmarksIndexFilename, 'r') as indexFile: - indexStr = indexFile.read().replace(bookmarkIndex + '\n', '') - indexStrChanged = True - if indexStrChanged: - bookmarksIndexFile = open(bookmarksIndexFilename, 'w') - if bookmarksIndexFile: - bookmarksIndexFile.write(indexStr) - bookmarksIndexFile.close() - def bookmarkedByPerson(postJsonObject: {}, nickname: str, domain: str) -> bool: """Returns True if the given post is bookmarked by the given person