-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckCumulativeTime.py
76 lines (56 loc) · 2.28 KB
/
checkCumulativeTime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import json
from collections import defaultdict
import webbrowser
import requests
import os
def genToken():
# alternatively remove the .get part if the browser is causing you an issue, or just open the url yourself and save the code to a file
webbrowser.get("x-www-browser").open("https://www.worldcubeassociation.org/oauth/authorize?client_id=5U1L9es8uMLPEPM_qbQuWWOqIY8NJiXcWC_4V1sLLgw&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=token&scope=manage_competitions+public",new=0)
token = input("A browser should open. Copy the token from the URL and paste it here")
return token
def getWcif(id):
if not os.path.exists("authcode"):
token = genToken()
with open('authcode','w') as f:
print(token,file=f)
else:
with open('authcode','r') as f:
token = f.readline().strip('\n')
header = {'Authorization':f"Bearer {token}"}
wcif = requests.get(f"https://www.worldcubeassociation.org/api/v0/competitions/{id}/wcif",headers=header)
assert wcif.status_code == 200
return wcif,header
# data = json.loads(get_wcif('HDCIIHvidovre2022').content)
response,header = getWcif('HDCIIHvidovre2022')
data = json.loads(response.content)
c = defaultdict(int)
dnfcounter = defaultdict(int)
for val in data["events"]:
for val2 in val['rounds']:
for val3 in val2['results']:
for val4 in val3['attempts']:
if val4['result'] > 0:
c[val3['personId']] +=val4['result']
elif val4['result'] == -1:
dnfcounter[val3['personId']] += 1
translater = {}
for val in data['persons']:
translater[val['registrantId']] = val['name']
def convert(seconds):
seconds = seconds/100
seconds = seconds % (24 * 3600)
hour = seconds // 3600
seconds %= 3600
minutes = seconds // 60
seconds %= 60
return "%d:%02d:%02d" % (hour, minutes, seconds)
overview = [(name,value) for name,value in c.items()]
which = 1 # 0 is by time, 1 is by name
if which == 0:
overview.sort(key=lambda x:x[1], reverse=True)
elif which == 1:
overview.sort(key=lambda x:translater[x[0]], reverse=False)
# for person in c:
# print(translater[person],convert(c[person]),dnfcounter[person])
for val in overview:
print(f"{translater[val[0]][:15]}\tTime used: {convert(c[val[0]])}\tDNFs: {dnfcounter[val[0]]}")