forked from TIOJ-INFOR-Online-Judge/tioj-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestdata_modify.py
More file actions
executable file
·102 lines (84 loc) · 3.22 KB
/
Copy pathtestdata_modify.py
File metadata and controls
executable file
·102 lines (84 loc) · 3.22 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""TIOJ AUTO MODIFY Testdata Script"""
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
import requests
import random
import string
from getpass import getpass as getpass
from bs4 import BeautifulSoup
# config
judge_site = 'https://tioj.ck.tp.edu.tw'
input_suffix = '.in'
output_suffix = '.out'
filename_format = '%d%s'
# end config
session = requests.Session()
def login():
TIOJusername = input('Username: ')
TIOJpassword = getpass('Password: ')
print('logging in...')
global session
rel = session.get(judge_site + '/users/sign_in')
soup = BeautifulSoup(rel.text, "html.parser")
inputs = soup.find('form').find_all('input')
data = {
'authenticity_token': inputs[0].attrs['value'],
'user[username]': TIOJusername,
'user[password]': TIOJpassword,
'user[remember_me]': '1',
'commit': 'Sign in'
}
rel = session.post(judge_site + '/users/sign_in', data=data)
login()
print('Successful log in')
problem_id = int(input('Problem ID: '))
num_start = int(input('Testdata start number: '))
num_end = int(input('Testdata end number: '))
time_limit = int(input('New time limit: '))
memory_limit = int(input('New memory limit: '))
upload_input = bool(input('Reupload input? 1 for yes. ') == "1")
upload_output = bool(input('Reupload output? 1 for yes. ') == "1")
url = judge_site + '/problems/%s/testdata' % problem_id
sign_up_get_url = judge_site + '/problems/%s/testdata/new' % problem_id
sign_up_post_url = judge_site + '/problems/%s/testdata' % problem_id
rel = session.get(url)
soup = BeautifulSoup(rel.text, "html.parser")
inputs = soup.find_all('a')
lst = []
for t in inputs:
st = str(t)
if st.find("btn btn-info btn-xs") != -1:
c = st.find("testdata") + 9
d = st.find("/", c)
val = int(st[c:d])
if not val in lst: lst.append(val)
lst = lst[num_start:num_end+1]
if len(lst) == 0: print('Error')
c = num_start
for i in lst:
print('processing %d(%d)...' % (c, i))
now_url = judge_site + '/problems/%s/testdata/%d/edit' % (problem_id, i)
post_url = now_url[:-5]
rel = session.get(now_url)
soup = BeautifulSoup(rel.text, "html.parser")
inputs = soup.find('form').find_all('input')
data = {
inputs[0].attrs['name']: inputs[0].attrs['value'],
inputs[1].attrs['name']: inputs[1].attrs['value'],
inputs[2].attrs['name']: inputs[2].attrs['value'],
'testdatum[limit_attributes][time]': time_limit,
'testdatum[limit_attributes][memory]': memory_limit,
'testdatum[limit_attributes][output]': '65536',
'testdatum[limit_attributes][id]': str(i),
'testdatum[problem_id]': problem_id,
'commit': 'Update Testdatum'
}
files = {}
if upload_input: files['testdatum[test_input]'] = open(filename_format % (c, input_suffix), 'rb')
if upload_output: files['testdatum[test_output]'] = open(filename_format % (c, output_suffix), 'rb')
rel = session.post(post_url, data = data, files = files)
print('Modify %d(%d)!!' % (c, i))
c += 1