Skip to content

Commit

Permalink
Made program wait until case is done
Browse files Browse the repository at this point in the history
  • Loading branch information
confestim committed Dec 2, 2024
1 parent c14f87a commit 5c3e884
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions temmies/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from typing import Optional, Union, Dict
from .exceptions.illegal_action import IllegalAction
from .submission import Submission
from json import loads
from time import sleep

class Group:
"""
Expand Down Expand Up @@ -280,14 +282,22 @@ def __wait_for_result(self, url: str, verbose: bool, __printed: list) -> dict:
def __parse_table(self, soup: BeautifulSoup, url: str, verbose: bool, __printed: list) -> dict:
"""
Parse the results table from the submission result page.
Wait until all queued status-icons disappear before parsing.
"""
cases = soup.find_all("tr", class_="sub-casetop")
fail_pass = {}
any_queued = False

for case in cases:
name = case.find("td", class_="sub-casename").text
name = case.find("td", class_="sub-casename").text.strip()
status = case.find("td", class_="status-icon")

if "pending" in status.get("class"):
status_classes = status.get("class", [])
if "queued" in status_classes:
any_queued = True
break

if "pending" in status_classes:
sleep(1)
return self.__wait_for_result(url, verbose, __printed)

Expand All @@ -299,20 +309,31 @@ def __parse_table(self, soup: BeautifulSoup, url: str, verbose: bool, __printed:
}

found = False
for k, v in statuses.items():
if k in status.text:
for key, (symbol, value) in statuses.items():
if key.lower() in status.text.lower():
found = True
if verbose and int(name) not in __printed:
print(f"{name}: {v[0]}")
fail_pass[int(name)] = v[1]
case_number = int(name)
if verbose and case_number not in __printed:
print(f"Case {case_number}: {symbol}")
fail_pass[case_number] = value
break

if not found:
fail_pass[int(name)] = None
if verbose and int(name) not in __printed:
print(f"{name}: Unrecognized status: {status.text}")
case_number = int(name)
fail_pass[case_number] = None
if verbose and case_number not in __printed:
print(f"{case_number}: Unrecognized status: {status.text.strip()}")

__printed.append(case_number)

# Polling
# FIXME: Use ws
if any_queued:
sleep(1)
return self.__wait_for_result(url, verbose, __printed)

__printed.append(int(name))
return fail_pass


def __str__(self):
return f"Group({self.title}, submitable={self.submitable})"

0 comments on commit 5c3e884

Please sign in to comment.