aboutsummaryrefslogtreecommitdiffstats
path: root/titlebot/commands/highest
diff options
context:
space:
mode:
authormakefu <root@pigstarter.de>2014-04-25 16:34:34 +0200
committermakefu <root@pigstarter.de>2014-04-25 16:34:34 +0200
commitc35e62e336afdcfc0123ff29ec99266a29a6e812 (patch)
treeeef1f236d98188d46bb63c7941d4af8e8566aa5f /titlebot/commands/highest
parent8284fc3b99e4647098e5a97c237dd77dcd68fb65 (diff)
add highest for titlebot
Diffstat (limited to 'titlebot/commands/highest')
-rwxr-xr-xtitlebot/commands/highest22
1 files changed, 22 insertions, 0 deletions
diff --git a/titlebot/commands/highest b/titlebot/commands/highest
new file mode 100755
index 0000000..5ac9ba9
--- /dev/null
+++ b/titlebot/commands/highest
@@ -0,0 +1,22 @@
+#!/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)
+limit = int(sys.argv[1]) if len(sys.argv) > 1 else 1
+num = 1
+# 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):
+ suffixed_num = str(num) + suffixes[num % 100]
+ print("%s: '%s' (%d votes)" %
+ (suffixed_num,entry['title'],sum(entry['votes'].values())))
+ num = num + 1
+ if num > limit:
+ sys.exit(0)