aboutsummaryrefslogtreecommitdiffstats
path: root/titlebot/commands/highest
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2014-04-27 18:17:23 +0200
committermakefu <github@syntax-fehler.de>2014-04-27 18:17:23 +0200
commit4b367ce717a91eda21337ff85a64fcb3f38db61d (patch)
tree84d2aa2aa045657afb573ed862c0510353e70e2e /titlebot/commands/highest
parent3005c4701cade073dbc2285e3629cb516b4a3cec (diff)
parent8ba1237707cf9da18344d2725e5d867f93dcd3c3 (diff)
Merge branch 'master' of ssh://github.com/krebscode/painload
Diffstat (limited to 'titlebot/commands/highest')
-rwxr-xr-xtitlebot/commands/highest30
1 files changed, 30 insertions, 0 deletions
diff --git a/titlebot/commands/highest b/titlebot/commands/highest
new file mode 100755
index 0000000..d0408ac
--- /dev/null
+++ b/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())))