import sys
import requests
import json
import time
import random
import string
import hashlib
contestids = ['ids of gyms you used for testing']
participants = set()
key = open('key', 'r').read()
secret = open('secret', 'r').read()
for contestid in contestids:
rand = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(6)])
params = [f'contestId={contestid}', 'showUnofficial=true', f'apiKey={key}', f'time={int(time.time())}']
req_params = '&'.join(params)
hash_params = '&'.join(sorted(params))
h = hashlib.sha512(f'{rand}/contest.standings?{hash_params}#{secret}'.encode('utf-8'))
sig = f'{rand}{h.hexdigest()}'
req = f'https://codeforces.com/api/contest.standings?{req_params}&apiSig={sig}'
standings = requests.get(req).json()['result']['rows']
for row in standings:
for participant in row['party']['members']:
participants.add(participant['handle'])
participants = list(participants)
bounds = [ 3000, 2400, 2100, 1900, 1600, 1400, 1200, -1000]
en_colors = ['red-black', 'red', 'yellow', 'purple', 'blue', 'cyan', 'green', 'grey']
rated_list = [[] for i in range(8)]
print(f'{len(participants)} testers:', *participants)
req = 'https://codeforces.com/api/user.info?handles='
for participant in participants:
req += participant + ';'
resp = requests.get(req)
while resp.status_code != 200:
time.sleep(1)
resp = requests.get(req)
resp = resp.json()['result']
for participant in resp:
for i in range(8):
if bounds[i] <= participant['rating']:
rated_list[i] += ['[user: ' + participant['handle'] + ']']
break
sys.stdout = open('en.txt', 'w')
for i in range(8):
if len(rated_list[i]) == 0:
continue
print(*rated_list[i], sep=', ', end=' ')
print(f'for {en_colors[i]} testing')