mirror of
https://github.com/davegallant/rfd.git
synced 2025-08-09 10:02:29 +00:00
19 lines
431 B
Python
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
|