From b36d5a81ced429778843f1480ce820e11ac7a1ea Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Wed, 6 Mar 2024 18:18:29 +0100 Subject: [PATCH] Fix names of classes and allow for combined competitions with other classes --- src/solo_turnier/competition_class.py | 47 +++++++++------------ src/solo_turnier/workers/ResultExtractor.py | 5 ++- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/solo_turnier/competition_class.py b/src/solo_turnier/competition_class.py index 019baae..1f4b46a 100644 --- a/src/solo_turnier/competition_class.py +++ b/src/solo_turnier/competition_class.py @@ -36,43 +36,34 @@ class CombinedCompetitionClass: Class_t = CompetitionClass | CombinedCompetitionClass -class CompetitionClassParser: - NEWC = CompetitionClass("Newc.") - BEG = CompetitionClass("Beg.") - ADV = CompetitionClass("Adv.") +class NoEClassException(Exception): + def __init__(self, *args): + super(NoEClassException, self).__init__(*args) - PREVIEW = CompetitionClass("Sichtung") + +class CompetitionClassParser: + E = CompetitionClass('E') def __init__(self): self.mapNames = { - "Newc": self.NEWC, - "Newc.": self.NEWC, - "Newcomer": self.NEWC, - "Beg": self.BEG, - "Beg.": self.BEG, - "Beginner": self.BEG, - "Adv": self.ADV, - "Adv.": self.ADV, - "Advanced": self.ADV, + "E": self.E, } self.namesPreview = ["Sichtung"] - self.mapShortNames = { - "N": self.NEWC, - "B": self.BEG, - "A": self.ADV, - } + self.mapShortNames = self.mapNames def parseClass(self, cls: str, allowPreview: bool = False) -> Class_t: - if allowPreview and cls in self.namesPreview: - return self.PREVIEW - - match = re.compile("^(\\w+\\.?)/(\\w+\\.?)$").match(cls) - if match is not None: - clsA = self.mapNames[match.group(1)] - clsB = self.mapNames[match.group(2)] - return CombinedCompetitionClass(clsA, clsB) - else: + # match = re.compile("^(\\w+\\.?)/(\\w+\\.?)$").match(cls) + # if match is not None: + # clsA = self.mapNames[match.group(1)] + # clsB = self.mapNames[match.group(2)] + # return CombinedCompetitionClass(clsA, clsB) + # else: + # return self.mapNames[cls] + + if cls in self.mapNames: return self.mapNames[cls] + else: + raise NoEClassException(f'The class "{cls}" is not parsable.') def parseAbbreviatedClass(self, cls: str) -> Class_t: return self.mapShortNames[cls] diff --git a/src/solo_turnier/workers/ResultExtractor.py b/src/solo_turnier/workers/ResultExtractor.py index 507794d..6fc5c0f 100644 --- a/src/solo_turnier/workers/ResultExtractor.py +++ b/src/solo_turnier/workers/ResultExtractor.py @@ -31,8 +31,11 @@ class ResultExtractor: try: data = parser.guessDataFromHtmlTitle() + except competition_class.NoEClassException as ex: + self.l.info('The HTML file %s does not represent a solo E class. Skipping it. (%s)', filePair[0], ex) + continue except: - self.l.error( + self.l.warning( "Cannot parse HTML file %s to check if it is a valid result. Check manually.", filePair[0], )