]> git.somenet.org - pub/jan/mattermost-bot.git/blob - json_stats_printer.py
modules/CommandDSARollDice.py
[pub/jan/mattermost-bot.git] / json_stats_printer.py
1 #!/usr/bin/env python3
2 #
3 # Mattermost Bot.
4 #  Copyright (c) 2016-2022 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
5 #  published under MIT-License
6 #
7 # This is started by the init script.
8 #
9
10 import json
11 import sys
12
13 def main():
14     with open(sys.argv[2], "r", encoding="utf-8") as f:
15         stats = json.load(f)
16
17         print(stats["header"])
18         if stats["data"]:
19             if sys.argv[1] == "code":
20                 print("```")
21             for c, count in sorted(stats["data"].items(), key=lambda x: x[1], reverse=True):
22                 if sys.argv[1] == "code":
23                     print(c+" ["+str(count)+"]")
24                 else:
25                     print("|"+sys.argv[3]+c+"|"+str(count)+"|")
26             if sys.argv[1] == "code":
27                 print("```")
28         else:
29             print(stats["no_data_text"])
30         print(stats["footer"])
31
32
33 main()