24 lines
681 B
Python
24 lines
681 B
Python
import json, os.path, sys, csv
|
|
from collections import Counter
|
|
|
|
with open(os.path.join(os.path.dirname(__file__),"badges.json")) as f: badges = json.load(f)
|
|
with open(os.path.join(os.path.dirname(__file__),"association.json")) as f: assoc = json.load(f)
|
|
|
|
users = []
|
|
|
|
for user in badges:
|
|
n=0
|
|
r=0
|
|
for badge in badges[user]:
|
|
if badge["name"]!="Tildebadge": continue
|
|
n+=1
|
|
r+=1 if badge["normal"] else 0
|
|
if n: users.append([assoc.get(user,user),n,"{:02.2%}".format(r/n)])
|
|
|
|
users.sort(key=lambda x: (-x[1],-float(x[2][:-1])))
|
|
seq = sorted([x[1] for x in users],reverse=True)
|
|
for i, u in enumerate(users):
|
|
u.insert(0,seq.index(u[1])+1)
|
|
|
|
csv.writer(sys.stdout).writerows(users)
|