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://mirror.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']
ru_colors = ['красно-чёрное', 'красное', 'жёлтое', 'фиолетовое', 'синее', 'бирюзовое', 'зелёное', 'серое']
rated_list = [[] for i in range(8)]
print(f'{len(participants)} testers:', *participants)
req = 'https://mirror.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('ru.txt', 'w', encoding='utf-8')
for i in range(8):
if len(rated_list[i]) == 0:
continue
print(*rated_list[i], sep=', ', end=' ')
print(f'за {ru_colors[i]} тестирование раунда')
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')
It's really funny, when everybody (including me in past) implements codeforces scripts in python, puts it in some folder and then forgets this folder, forgets that it exists and how to use it. And of course implements api requests in each script from scratch
9 month ago I implemented typescript SDK. It's really easier to implement any script with SDK and strict types: just look into your script, but rewritten with SDK
Which advantages does it have?
npx codeforces --help
npx codeforces <script> --help
myyour python script without virtualenv was broken after system update?)Disadvantages:
ContestId
Links:
Oh, we're advertising SDKs? Might I add my Polygon SDK for Go?
Thanx for the question, I understood that I forgot to explicitly state my point:
As long as ad of SDK (any SDK, yes), I strongly advice to make any scripts as mainainable as possible: it's not codeforces problem, it has different goals and usages. And do not forget that you are not on contest!
contestids = ['ids of gyms you used for testing']
withcontestids = sys.argv[1:]
and addingif len(sys.argv) == 1: print('Usage: ...')
will drastically improve this script