Skip to content

Commit

Permalink
Remove lxml dependency; fetch data directly from ?json endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelNiemela committed Aug 17, 2024
1 parent 090d32c commit 4228e8f
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import requests
import requests.exceptions

from lxml.html import fragment_fromstring

# Python 2/3 compatibility
if sys.version_info[0] >= 3:
import configparser
Expand Down Expand Up @@ -324,8 +322,10 @@ def show_judgement(submission_url, cfg):
status = get_submission_status(submission_url, login_reply.cookies)
status_id = status['status_id']
score = status['score']
runtime = status['runtime']
testcases_done = status['testcase_index']
testcases_total = status['row_html'].count('<i') - 1
testcases_total = int(status['testcase_count'])
compiler_feedback = status['compiler_feedback']

status_text = _STATUS_MAP.get(status_id, 'Unknown status %s' % status_id)

Expand All @@ -337,13 +337,9 @@ def show_judgement(submission_url, cfg):

if status_id == _COMPILE_ERROR_STATUS:
print('\r%s' % color(status_text, _RED_COLOR), end='')
try:
root = fragment_fromstring(status['feedback_html'], create_parent=True)
error = root.find('.//pre').text
if compiler_feedback:
print(color(':', _RED_COLOR))
print(error, end='')
except:
pass
print(compiler_feedback, end='')
elif status_id < _RUNNING_STATUS:
print('\r%s...' % (status_text), end='')
else:
Expand All @@ -370,12 +366,7 @@ def show_judgement(submission_url, cfg):
success = status_id == _ACCEPTED_STATUS
if success:
status_text += f' ({score})'
try:
root = fragment_fromstring(status['row_html'], create_parent=True)
cpu_time = root.find('.//*[@data-type="cpu"]').text
status_text += f' ({cpu_time})'
except:
pass
status_text += f' ({runtime} s)'
if status_id != _COMPILE_ERROR_STATUS:
print(color(status_text, _GREEN_COLOR if success else _RED_COLOR))
return success
Expand Down

0 comments on commit 4228e8f

Please sign in to comment.