-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_result.py
79 lines (67 loc) · 2.96 KB
/
check_result.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
69
70
71
72
73
74
75
76
77
78
79
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class Check_Result:
def __init__(self, headless = True):
if headless:
options = webdriver.ChromeOptions()
options.add_argument("headless")
self.driver = webdriver.Chrome(options = options)
else:
self.driver = webdriver.Chrome()
self.status_url = "https://www.acmicpc.net/status?top="
def get_result(self, submission_id):
"""
Returns (problem_id, result) for given submission id.
Do not call this function outside.
This function WAITS until the submission's result comes out.
"""
desired_url = self.status_url + str(submission_id)
self.driver.get(desired_url)
table = self.driver.find_element(By.ID, "status-table")
tbody = table.find_element(By.TAG_NAME, "tbody")
entries = tbody.find_elements(By.TAG_NAME, "tr")
if len(entries) == 0:
raise Exception("submission not found")
entry = entries[0]
elems = entry.find_elements(By.TAG_NAME, "td")
submission_wid = int(elems[0].text)
assert(submission_id == submission_wid)
problem_id = int(elems[2].text)
wait300 = WebDriverWait(self.driver, 300)
result_locator = (By.XPATH, '//tr[@id="solution-{}"]//td[@class="result"]//span'.format(submission_id))
cond1 = EC.text_to_be_present_in_element(result_locator, '기다리는 중')
cond2 = EC.text_to_be_present_in_element(result_locator, '채점 준비 중')
cond3 = EC.text_to_be_present_in_element(result_locator, '채점 중')
wait300.until(EC.none_of(cond1, cond2, cond3))
result = elems[3].text
return (problem_id, result)
def check_result(self, old_submission_id, new_submission_id):
"""
Checks if the results of two submission ids are equivalent.
will return True if they are the same,
or it will return information about incorrect submission results.
"""
(old_problem_number, old_result) = self.get_result(old_submission_id)
(new_problem_number, new_result) = self.get_result(new_submission_id)
if old_problem_number != new_problem_number:
raise Exception("found mismatching submission pair")
if old_result == new_result:
return True
else:
return "Incorrect submission result for Problem {} : Expected {}, but got {}".format(
old_problem_number, old_result, new_result)
"""
checkEngine = Check_Result()
old_id = input("Old Submission ID: ")
new_id = input("New Submission ID: ")
result = checkEngine.check_result(old_id, new_id)
print(result)
"""
"""
checkEngine = Check_Result()
while True:
submission_id = input("Submission ID: ")
print(checkEngine.get_result(submission_id))
"""