#!/usr/bin/env python3 import datetime import re from typing import Dict, List class Submission: MAIL_CONTENT = re.compile(r"
((.*\s+)+)<\/pre>") def __init__( self, uco: str, login: str, path: str, submission_id: str, points: float, homework: str, correction: bool, mail: str, ) -> None: self.uco = uco self.login = login self.path = path self.submission_id = submission_id self.points = points self.homework = homework self.correction = correction self.mail = mail self.submitted_at = None self.submitted_before_deadline = None self.flag = None self.branch = f"{homework}{'-opravne' if correction else ''}-{login}" self.__set_submission_date() def __set_submission_date(self) -> None: self.submitted_at = datetime.datetime.strptime( self.submission_id[-16:], "%Y_%m%d_%H%M%S" ) def set_late_tag(self, deadline: datetime.datetime) -> None: self.submitted_before_deadline = self.submitted_at < deadline if not self.submitted_before_deadline: self.flag = "LATE" def get_mail(self) -> str: left = self.mail.find("") right = self.mail.rfind("") return self.mail[left + 5 : right] def print_submissions(all_submissions: Dict[str, List[Submission]]) -> None: header = ( "| " + " | ".join( [ "###", "UCO".center(6), "LOGIN".center(8), "SUBMITTED".center(19), "POINTS", "FLAG".center(6), ] ) + " |" ) SEPARATOR = "-" * len(header) print(SEPARATOR) print(header) print(SEPARATOR) FORMAT = "| {:>3} | {:>6s} | {:>8s} | {} | {:>6.2f} | {:^6s} |" for _, submissions in all_submissions.items(): for i, submission in enumerate(submissions): date = submission.submitted_at.strftime("%Y-%m-%d %H:%M:%S") print( FORMAT.format( i, submission.uco if i == 0 else "", submission.login if i == 0 else "", date, submission.points, submission.flag if submission.flag else "", ) ) print(SEPARATOR)