mirror of https://gitlab.com/bashrc2/epicyon
Less indentation
parent
2099788bcd
commit
cd14cc2775
93
utils.py
93
utils.py
|
@ -1800,6 +1800,7 @@ def searchBoxPosts(baseDir: str, nickname: str, domain: str,
|
||||||
containing matching strings
|
containing matching strings
|
||||||
"""
|
"""
|
||||||
path = baseDir + '/accounts/' + nickname + '@' + domain + '/' + boxName
|
path = baseDir + '/accounts/' + nickname + '@' + domain + '/' + boxName
|
||||||
|
# is this a virtual box, such as direct messages?
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
if os.path.isfile(path + '.index'):
|
if os.path.isfile(path + '.index'):
|
||||||
return _searchVirtualBoxPosts(baseDir, nickname, domain,
|
return _searchVirtualBoxPosts(baseDir, nickname, domain,
|
||||||
|
@ -1854,54 +1855,56 @@ def undoLikesCollectionEntry(recentPostsCache: {},
|
||||||
"""Undoes a like for a particular actor
|
"""Undoes a like for a particular actor
|
||||||
"""
|
"""
|
||||||
postJsonObject = loadJson(postFilename)
|
postJsonObject = loadJson(postFilename)
|
||||||
if postJsonObject:
|
if not postJsonObject:
|
||||||
# remove any cached version of this post so that the
|
return
|
||||||
# like icon is changed
|
# remove any cached version of this post so that the
|
||||||
nickname = getNicknameFromActor(actor)
|
# like icon is changed
|
||||||
cachedPostFilename = getCachedPostFilename(baseDir, nickname,
|
nickname = getNicknameFromActor(actor)
|
||||||
domain, postJsonObject)
|
cachedPostFilename = getCachedPostFilename(baseDir, nickname,
|
||||||
if cachedPostFilename:
|
domain, postJsonObject)
|
||||||
if os.path.isfile(cachedPostFilename):
|
if cachedPostFilename:
|
||||||
os.remove(cachedPostFilename)
|
if os.path.isfile(cachedPostFilename):
|
||||||
removePostFromCache(postJsonObject, recentPostsCache)
|
os.remove(cachedPostFilename)
|
||||||
|
removePostFromCache(postJsonObject, recentPostsCache)
|
||||||
|
|
||||||
if not postJsonObject.get('type'):
|
if not postJsonObject.get('type'):
|
||||||
return
|
return
|
||||||
if postJsonObject['type'] != 'Create':
|
if postJsonObject['type'] != 'Create':
|
||||||
return
|
return
|
||||||
if not hasObjectDict(postJsonObject):
|
if not hasObjectDict(postJsonObject):
|
||||||
if debug:
|
if debug:
|
||||||
pprint(postJsonObject)
|
pprint(postJsonObject)
|
||||||
print('DEBUG: post ' + objectUrl + ' has no object')
|
print('DEBUG: post ' + objectUrl + ' has no object')
|
||||||
return
|
return
|
||||||
if not postJsonObject['object'].get('likes'):
|
if not postJsonObject['object'].get('likes'):
|
||||||
return
|
return
|
||||||
if not isinstance(postJsonObject['object']['likes'], dict):
|
if not isinstance(postJsonObject['object']['likes'], dict):
|
||||||
return
|
return
|
||||||
if not postJsonObject['object']['likes'].get('items'):
|
if not postJsonObject['object']['likes'].get('items'):
|
||||||
return
|
return
|
||||||
totalItems = 0
|
totalItems = 0
|
||||||
if postJsonObject['object']['likes'].get('totalItems'):
|
if postJsonObject['object']['likes'].get('totalItems'):
|
||||||
totalItems = postJsonObject['object']['likes']['totalItems']
|
totalItems = postJsonObject['object']['likes']['totalItems']
|
||||||
itemFound = False
|
itemFound = False
|
||||||
for likeItem in postJsonObject['object']['likes']['items']:
|
for likeItem in postJsonObject['object']['likes']['items']:
|
||||||
if likeItem.get('actor'):
|
if likeItem.get('actor'):
|
||||||
if likeItem['actor'] == actor:
|
if likeItem['actor'] == actor:
|
||||||
if debug:
|
|
||||||
print('DEBUG: like was removed for ' + actor)
|
|
||||||
postJsonObject['object']['likes']['items'].remove(likeItem)
|
|
||||||
itemFound = True
|
|
||||||
break
|
|
||||||
if itemFound:
|
|
||||||
if totalItems == 1:
|
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: likes was removed from post')
|
print('DEBUG: like was removed for ' + actor)
|
||||||
del postJsonObject['object']['likes']
|
postJsonObject['object']['likes']['items'].remove(likeItem)
|
||||||
else:
|
itemFound = True
|
||||||
itlen = len(postJsonObject['object']['likes']['items'])
|
break
|
||||||
postJsonObject['object']['likes']['totalItems'] = itlen
|
if not itemFound:
|
||||||
|
return
|
||||||
|
if totalItems == 1:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: likes was removed from post')
|
||||||
|
del postJsonObject['object']['likes']
|
||||||
|
else:
|
||||||
|
itlen = len(postJsonObject['object']['likes']['items'])
|
||||||
|
postJsonObject['object']['likes']['totalItems'] = itlen
|
||||||
|
|
||||||
saveJson(postJsonObject, postFilename)
|
saveJson(postJsonObject, postFilename)
|
||||||
|
|
||||||
|
|
||||||
def updateLikesCollection(recentPostsCache: {},
|
def updateLikesCollection(recentPostsCache: {},
|
||||||
|
|
Loading…
Reference in New Issue