Handle missing items list

main2
Bob Mottram 2019-09-11 17:09:53 +01:00
parent 89f72579ca
commit 4004e231e5
1 changed files with 12 additions and 14 deletions

26
like.py
View File

@ -117,20 +117,18 @@ def updateLikesCollection(postFilename: str,objectUrl: str, actor: str,debug: bo
}
postJsonObject['object']['likes']=likesJson
else:
if postJsonObject['object']['likes'].get('items'):
for likeItem in postJsonObject['object']['likes']['items']:
if likeItem.get('actor'):
if likeItem['actor']==actor:
return
newLike={
'type': 'Like',
'actor': actor
}
postJsonObject['object']['likes']['items'].append(newLike)
postJsonObject['object']['likes']['totalItems']=len(postJsonObject['likes']['items'])
else:
if debug:
print('DEBUG: likes section of post has no items list')
if not postJsonObject['object']['likes'].get('items'):
postJsonObject['object']['likes']['items']=[]
for likeItem in postJsonObject['object']['likes']['items']:
if likeItem.get('actor'):
if likeItem['actor']==actor:
return
newLike={
'type': 'Like',
'actor': actor
}
postJsonObject['object']['likes']['items'].append(newLike)
postJsonObject['object']['likes']['totalItems']=len(postJsonObject['likes']['items'])
if debug:
print('DEBUG: saving post with likes added')