Removing bookmarks from index

merge-requests/30/head
Bob Mottram 2019-11-18 15:21:35 +00:00
parent 3b83a30e41
commit 79789014d4
1 changed files with 69 additions and 59 deletions

View File

@ -29,7 +29,9 @@ def undoBookmarksCollectionEntry(baseDir: str,postFilename: str,objectUrl: str,
"""Undoes a bookmark for a particular actor
"""
postJsonObject=loadJson(postFilename)
if postJsonObject:
if not postJsonObject:
return
# remove any cached version of this post so that the bookmark icon is changed
nickname=getNicknameFromActor(actor)
cachedPostFilename= \
@ -66,7 +68,10 @@ def undoBookmarksCollectionEntry(baseDir: str,postFilename: str,objectUrl: str,
postJsonObject['object']['bookmarks']['items'].remove(bookmarkItem)
itemFound=True
break
if itemFound:
if not itemFound:
return
if totalItems==1:
if debug:
print('DEBUG: bookmarks was removed from post')
@ -78,13 +83,18 @@ def undoBookmarksCollectionEntry(baseDir: str,postFilename: str,objectUrl: str,
# remove from the index
bookmarksIndexFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/bookmarks.index'
if os.path.isfile(bookmarksIndexFilename):
bookmarkIndex=postFilename.split('/')[-1]+'\n'
if bookmarkIndex in open(bookmarksIndexFilename).read():
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,'')
indexStr=indexFile.read().replace(bookmarkIndex+'\n','')
indexStrChanged=True
if indexStrChanged:
bookmarksIndexFile=open(bookmarksIndexFilename,'w')