fix: Make sure to use ints
All checks were successful
Build Docker / Build Image (push) Successful in 21s

This commit is contained in:
Nathan Woodburn 2024-02-25 21:52:04 +11:00
parent b3d9e66916
commit 84f8388e39
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -9,21 +9,23 @@ def votes():
print(votes) print(votes)
options = {} options = {}
for vote in votes: for vote in votes:
# Check if message is json # Check if message is json
if 'votes' not in vote:
continue
weight = int(vote["votes"])
if vote["message"].startswith("{"): if vote["message"].startswith("{"):
message = json.loads(vote["message"]) message = json.loads(vote["message"])
for key in message: for key in message:
if key in options: if key in options:
options[key] += (int(message[key]) * int(vote["votes"])) options[key] += (int(message[key]) * weight)
else: else:
options[key] = (int(message[key]) * int(vote["votes"])) options[key] = (int(message[key]) * weight)
continue continue
if vote["message"] in options: if vote["message"] in options:
options[vote["message"]] += vote["votes"] options[vote["message"]] += weight
else: else:
options[vote["message"]] = vote["votes"] options[vote["message"]] = weight
labels = list(options.keys()) labels = list(options.keys())