Files
rfd/rfd/scores.py
Dave Gallant be92e5773d fix bug when iterating over all existing posts in a thread (#23)
* fix get posts

* remove tail/head and fix posts command
2019-09-15 23:21:40 -04:00

19 lines
431 B
Python

def calculate_score(post):
"""Calculate either topic or post score. If votes cannot be retrieved, the score is 0.
Arguments:
post {dict} -- pass in the topic/post object
Returns:
int -- score
"""
score = 0
try:
score = int(post.get("votes").get("total_up")) - int(
post.get("votes").get("total_down")
)
except AttributeError:
pass
return score