aboutsummaryrefslogtreecommitdiffstats
path: root/titlebot/commands
diff options
context:
space:
mode:
Diffstat (limited to 'titlebot/commands')
-rwxr-xr-xtitlebot/commands/highest22
-rwxr-xr-xtitlebot/commands/list4
2 files changed, 24 insertions, 2 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)
diff --git a/titlebot/commands/list b/titlebot/commands/list
index 3a29919..cee4b8a 100755
--- a/titlebot/commands/list
+++ b/titlebot/commands/list
@@ -17,11 +17,11 @@ if len(sys.argv) > 1 and ("-h" in sys.argv[1] or "usage" == sys.argv[1]):
if len(sys.argv) > 1 and ("votes" in sys.argv[1]):
use = poll.sort_by_votes(db)
elif len(sys.argv) > 1 and ("age" in sys.argv[1]) or len(sys.argv) == 1:
- pass
+ use = db
else:
print("unknown sorting method")
sys.exit(1)
-for entry in poll.sort_by_votes(db):
+for entry in use:
print("#%d %s (votes: %d)" %
(db.index(entry),entry['title'],sum(entry['votes'].values())))