diff options
author | root <root@flap> | 2014-05-06 10:00:33 -0400 |
---|---|---|
committer | root <root@flap> | 2014-05-06 10:00:33 -0400 |
commit | 4d8016064edd5e5dc1d194ea5ec0fce4f07b8f2a (patch) | |
tree | d8ecba8651604e51d6f887449641ac627844ae63 /Reaktor/titlebot/commands/highest | |
parent | f44c8529e6d04b557d93cc862599b956ed21f0de (diff) | |
parent | d0367082a5c1296cefed641b4eda736b29a3ad69 (diff) |
Merge branch 'master' of https://github.com/krebscode/painload
Diffstat (limited to 'Reaktor/titlebot/commands/highest')
-rwxr-xr-x | Reaktor/titlebot/commands/highest | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Reaktor/titlebot/commands/highest b/Reaktor/titlebot/commands/highest new file mode 100755 index 00000000..d0408ac0 --- /dev/null +++ b/Reaktor/titlebot/commands/highest @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +import json +from os import environ +import sys +import os +import poll + +f = 'suggestions.json' +title=" ".join(sys.argv[1:]) +db = poll.load_db(f) +# only print the last N values (default 1) +limit = int(sys.argv[1]) if len(sys.argv) > 1 else 1 +num = 0 +last_vote = 9001 +# stolen from http://stackoverflow.com/questions/9647202/ordinal-numbers-replacement +suffixes = ["th", "st", "nd", "rd", ] + ["th"] * 16 + +for entry in poll.sort_by_votes(db): + # if two entries have the same number of upvotes, do not increment the rank + current_vote = sum(entry['votes'].values()) + if current_vote < last_vote: + num = num + 1 + last_vote = current_vote + # exit if we are above the limit + if num > limit: + sys.exit(0) + + suffixed_num = str(num) + suffixes[num % 100] + print("%s: '%s' (%d votes)" % + (suffixed_num,entry['title'],sum(entry['votes'].values()))) |