Make the output of list_badges useful

This commit is contained in:
Robert Miles 2020-02-25 14:08:13 -05:00
parent d4782dab33
commit b31b30c48f
1 changed files with 10 additions and 3 deletions

View File

@ -1,12 +1,19 @@
import json
import json, os.path
from collections import Counter
with open("badges.json") as f: badges = json.load(f)
with open(os.path.join(os.path.dirname(__file__),"badges.json")) as f: badges = json.load(f)
users = []
for k in badges:
if k.startswith("__"): continue
l = []
counter = Counter([b["name"] for b in badges[k]])
total = 0
for item in counter.items():
l.append("{} (x{!s})".format(*item))
print("{}: {}".format(k,", ".join(l)))
total+=item[1]
users.append([k,", ".join(l),total])
users.sort(key=lambda x: -x[2])
for user in users: print(": ".join(user[:-1]))