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 postJsonObject['object']['likes']=likesJson
else: else:
if postJsonObject['object']['likes'].get('items'): if not postJsonObject['object']['likes'].get('items'):
for likeItem in postJsonObject['object']['likes']['items']: postJsonObject['object']['likes']['items']=[]
if likeItem.get('actor'): for likeItem in postJsonObject['object']['likes']['items']:
if likeItem['actor']==actor: if likeItem.get('actor'):
return if likeItem['actor']==actor:
newLike={ return
'type': 'Like', newLike={
'actor': actor 'type': 'Like',
} 'actor': actor
postJsonObject['object']['likes']['items'].append(newLike) }
postJsonObject['object']['likes']['totalItems']=len(postJsonObject['likes']['items']) postJsonObject['object']['likes']['items'].append(newLike)
else: postJsonObject['object']['likes']['totalItems']=len(postJsonObject['likes']['items'])
if debug:
print('DEBUG: likes section of post has no items list')
if debug: if debug:
print('DEBUG: saving post with likes added') print('DEBUG: saving post with likes added')