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/list | |
parent | f44c8529e6d04b557d93cc862599b956ed21f0de (diff) | |
parent | d0367082a5c1296cefed641b4eda736b29a3ad69 (diff) |
Merge branch 'master' of https://github.com/krebscode/painload
Diffstat (limited to 'Reaktor/titlebot/commands/list')
-rwxr-xr-x | Reaktor/titlebot/commands/list | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Reaktor/titlebot/commands/list b/Reaktor/titlebot/commands/list new file mode 100755 index 00000000..cee4b8a8 --- /dev/null +++ b/Reaktor/titlebot/commands/list @@ -0,0 +1,27 @@ +#!/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) +if len(sys.argv) > 1 and ("-h" in sys.argv[1] or "usage" == sys.argv[1]): + print("""usage: list <(age|votes)> + sort by age or by votes (default: age) +""") + sys.exit(0) + +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: + use = db +else: + print("unknown sorting method") + sys.exit(1) + +for entry in use: + print("#%d %s (votes: %d)" % + (db.index(entry),entry['title'],sum(entry['votes'].values()))) |