-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.py
68 lines (55 loc) · 2.08 KB
/
submit.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
import csv
import os
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder
usernameToToken = {}
aliasToProblemJid = {
'A': 'JIDPROGxxx',
'B': 'JIDPROGxxx',
'C': 'JIDPROGxxx',
'D': 'JIDPROGxxx',
'E': 'JIDPROGxxx',
'F': 'JIDPROGxxx'
}
contestJid = 'JIDCONTxxx'
with open('tokens.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
username = row[0]
token = row[1]
usernameToToken[username] = token
def submit(username, problemAlias, gradingLanguage, filename, solution, cnt):
multi_part = MultipartEncoder(
fields={
'contestJid': contestJid,
'problemJid': aliasToProblemJid[problemAlias],
'gradingLanguage': gradingLanguage,
'sourceFiles.source': (filename, solution, 'application/octet-stream')
}
)
headers = {
'Authorization': 'Bearer ' + usernameToToken[username],
'Content-Type': multi_part.content_type
}
url = 'https://api.judgels/v2/contests/submissions/programming'
print('Submitting {} - {} - {} ... '.format(problemAlias, cnt, username), end='')
response = requests.post(url, data=multi_part, headers=headers)
print(response.status_code, flush=True)
for problemAlias in aliasToProblemJid.keys():
cnt = 0
for dirname in sorted(os.listdir('../by-problem/{}'.format(problemAlias))):
if dirname.startswith('.'):
continue
username = dirname.split(' - ')[0]
for filename in os.listdir('../by-problem/{}/{}'.format(problemAlias, dirname)):
if filename.endswith('_textresponse'):
continue
gradingLanguage = ''
if filename.endswith('.c'):
gradingLanguage = 'C'
else:
gradingLanguage = 'Cpp20'
with open('../by-problem/{}/{}/{}'.format(problemAlias, dirname, filename), 'rb') as file:
solution = file.read()
cnt += 1
submit(username, problemAlias, gradingLanguage, filename, solution, cnt)