mirror of https://gitlab.com/bashrc2/epicyon
Count likes on announces
parent
bde8dadce0
commit
21ec5ca9de
25
like.py
25
like.py
|
@ -41,7 +41,12 @@ def likedByPerson(postJsonObject: {}, nickname: str, domain: str) -> bool:
|
||||||
if noOfLikes(postJsonObject) == 0:
|
if noOfLikes(postJsonObject) == 0:
|
||||||
return False
|
return False
|
||||||
actorMatch = domain + '/users/' + nickname
|
actorMatch = domain + '/users/' + nickname
|
||||||
for item in postJsonObject['object']['likes']['items']:
|
|
||||||
|
obj = postJsonObject
|
||||||
|
if hasObjectDict(postJsonObject):
|
||||||
|
obj = postJsonObject['object']
|
||||||
|
|
||||||
|
for item in obj['likes']['items']:
|
||||||
if item['actor'].endswith(actorMatch):
|
if item['actor'].endswith(actorMatch):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -50,16 +55,17 @@ def likedByPerson(postJsonObject: {}, nickname: str, domain: str) -> bool:
|
||||||
def noOfLikes(postJsonObject: {}) -> int:
|
def noOfLikes(postJsonObject: {}) -> int:
|
||||||
"""Returns the number of likes ona given post
|
"""Returns the number of likes ona given post
|
||||||
"""
|
"""
|
||||||
if not hasObjectDict(postJsonObject):
|
obj = postJsonObject
|
||||||
|
if hasObjectDict(postJsonObject):
|
||||||
|
obj = postJsonObject['object']
|
||||||
|
if not obj.get('likes'):
|
||||||
return 0
|
return 0
|
||||||
if not postJsonObject['object'].get('likes'):
|
if not isinstance(obj['likes'], dict):
|
||||||
return 0
|
return 0
|
||||||
if not isinstance(postJsonObject['object']['likes'], dict):
|
if not obj['likes'].get('items'):
|
||||||
return 0
|
obj['likes']['items'] = []
|
||||||
if not postJsonObject['object']['likes'].get('items'):
|
obj['likes']['totalItems'] = 0
|
||||||
postJsonObject['object']['likes']['items'] = []
|
return len(obj['likes']['items'])
|
||||||
postJsonObject['object']['likes']['totalItems'] = 0
|
|
||||||
return len(postJsonObject['object']['likes']['items'])
|
|
||||||
|
|
||||||
|
|
||||||
def _like(recentPostsCache: {},
|
def _like(recentPostsCache: {},
|
||||||
|
@ -428,6 +434,7 @@ def updateLikesCollection(recentPostsCache: {},
|
||||||
obj = postJsonObject
|
obj = postJsonObject
|
||||||
if hasObjectDict(postJsonObject):
|
if hasObjectDict(postJsonObject):
|
||||||
obj = postJsonObject['object']
|
obj = postJsonObject['object']
|
||||||
|
|
||||||
if not objectUrl.endswith('/likes'):
|
if not objectUrl.endswith('/likes'):
|
||||||
objectUrl = objectUrl + '/likes'
|
objectUrl = objectUrl + '/likes'
|
||||||
if not obj.get('likes'):
|
if not obj.get('likes'):
|
||||||
|
|
Loading…
Reference in New Issue