Fix names of classes and allow for combined competitions with other classes

This commit is contained in:
Christian Wolf 2024-03-06 18:18:29 +01:00
parent 8d227af0e4
commit b36d5a81ce
2 changed files with 23 additions and 29 deletions

View File

@ -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]

View File

@ -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],
)