-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_problem.py
53 lines (47 loc) · 1.5 KB
/
add_problem.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
import requests
import json
import sys
from config import *
def add_execute(pid, name='New Execute /', language_id=1, execute = '{}', filename='main.c'):
parm={
'name' : name,
'problem_id' : pid,
'language_id' : language_id,
'execute' : execute,
'filename' : filename
}
url = 'https://api.oj.nctu.edu.tw/executes/'
rsp = requests.session().post(url, data=parm, cookies=COOKIES)
print( pid, json.loads(rsp.content) )
return json.loads(rsp.content)['msg']['id']
def add_executes(pid):
print( add_execute(pid,'C++17',2,executes['cpp17'],'main.cpp') )
print( add_execute(pid,'C11',1,executes['c11'],'main.c') )
print( add_execute(pid,'Java',3,executes['java'],'Main.java') )
print( add_execute(pid,'Python3',5,executes['py3'],'main.py') )
print( add_execute(pid,'Python2',4,executes['py2'],'main.py') )
def add_problem(title="HWX-X"):
parm={
'group_id': config['group_id'],
'title': title,
'visible': 0,
'group_read': 1,
'group_write': 1,
'use_pdf': 0,
'description': '',
'input': '',
'output': '',
'hint': '',
'source': ''
}
rsp = requests.session().post('https://api.oj.nctu.edu.tw/problems/', data=parm, cookies=COOKIES)
print(rsp)
pid = json.loads(rsp.content)['msg']['id']
add_executes(pid)
def main():
if len(sys.argv) >= 2:
add_problem(sys.argv[1])
else:
add_problem()
if __name__ == '__main__':
main()