summaryrefslogtreecommitdiffstats
path: root/Reaktor
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
commitda5b4578c07838d7c8c5c1c923ea03895e19a0da (patch)
treeca965893ec0b04ff510b2a5112cc57e59f6f4ab9 /Reaktor
parent2d646912b01c3e9399c19347b524ebbe00f44a04 (diff)
add highest for titlebot
Diffstat (limited to 'Reaktor')
-rwxr-xr-xReaktor/titlebot/commands/highest22
-rwxr-xr-xReaktor/titlebot/commands/list4
-rw-r--r--Reaktor/titlebot/titlebot.py1
3 files changed, 25 insertions, 2 deletions
diff --git a/Reaktor/titlebot/commands/highest b/Reaktor/titlebot/commands/highest
new file mode 100755
index 00000000..5ac9ba99
--- /dev/null
+++ b/Reaktor/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/Reaktor/titlebot/commands/list b/Reaktor/titlebot/commands/list
index 3a29919a..cee4b8a8 100755
--- a/Reaktor/titlebot/commands/list
+++ b/Reaktor/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())))
diff --git a/Reaktor/titlebot/titlebot.py b/Reaktor/titlebot/titlebot.py
index 6a3b2f79..c1eac3b0 100644
--- a/Reaktor/titlebot/titlebot.py
+++ b/Reaktor/titlebot/titlebot.py
@@ -60,6 +60,7 @@ public_commands = [
default_command('nocommand'),
titlebot_cmd('list'),
titlebot_cmd('help'),
+ titlebot_cmd('highest'),
titlebot_cmd('up'),
titlebot_cmd('new'),
titlebot_cmd('undo'),