Skip to content

Commit

Permalink
Split off some functionality into its own function
Browse files Browse the repository at this point in the history
  • Loading branch information
madeddie committed May 20, 2024
1 parent b2af18f commit bd13201
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions tyora.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,25 @@ def print_task(task: Task) -> None:
# with open(filename, 'r') as f:


def parse_submit_result(html: AnyStr) -> dict[str, str]:
root = htmlement.fromstring(html)
submit_status_element = root.find('.//td[.="Status:"]/..') or Element("td")
submit_status_span_element = submit_status_element.find("td/span") or Element(
"span"
)
submit_status = submit_status_span_element.text or ""
submit_result_element = root.find('.//td[.="Result:"]/..') or Element("td")
submit_result_span_element = submit_result_element.find("td/span") or Element(
"span"
)
submit_result = submit_result_span_element.text or ""

return {
"status": submit_status.lower(),
"result": submit_result.lower(),
}


def main() -> None:
args = parse_args()

Expand Down Expand Up @@ -462,20 +481,10 @@ def main() -> None:
html = session.http_request(result_url)

print()
root = htmlement.fromstring(html)
submit_status_element = root.find('.//td[.="Status:"]/..') or Element("td")
submit_status_span_element = submit_status_element.find("td/span") or Element(
"span"
)
submit_status = submit_status_span_element.text or ""
submit_result_element = root.find('.//td[.="Result:"]/..') or Element("td")
submit_result_span_element = submit_result_element.find("td/span") or Element(
"span"
)
submit_result = submit_result_span_element.text or ""
results = parse_submit_result(html)

print(f"Submission status: {submit_status.lower()}")
print(f"Submission result: {submit_result.lower()}")
print(f"Submission status: {results['status']}")
print(f"Submission result: {results['result']}")


if __name__ == "__main__":
Expand Down

0 comments on commit bd13201

Please sign in to comment.