From ff88ca056fffe4bfbaefa06c197429f0560e9a6c Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Sun, 27 Apr 2025 12:23:15 +0200 Subject: [PATCH] Fix parsinf for some ESV mails --- .../competitionParser.py | 50 ++++++++++++------- scripts/read-competition-notification/run.sh | 2 + 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/scripts/read-competition-notification/competitionNotificationReader/competitionParser.py b/scripts/read-competition-notification/competitionNotificationReader/competitionParser.py index db984dd..5fa8b09 100644 --- a/scripts/read-competition-notification/competitionNotificationReader/competitionParser.py +++ b/scripts/read-competition-notification/competitionNotificationReader/competitionParser.py @@ -4,7 +4,7 @@ import re import os import jinja2 -class ParsingFailedEception(Exception): +class ParsingFailedException(Exception): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -30,9 +30,16 @@ class CompetitionParser: self._reNumber = re.compile('Turnier: ([0-9]+)') self._rePhone = re.compile('Telefon: (\\+?[0-9 /-]+)') self._rePlace = re.compile('Ort: (.*), (.*)') - self._reCompetition = re.compile('(.*) ([A-ES]) ((?:Std)|(?:Lat)|(?:Kombi))') + self._reCompetition = re.compile('(.*) ([A-ES]) ((?:Std)|(?:Lat)|(?:Kombi)|(?:Kmb))') + self._reCompetitionSectionMap = { + 'Std': 'Std', + 'Lat': 'Lat', + 'Kombi': 'Kombi', + 'Kmb': 'Kombi', + } self._reWDSFCompetition = re.compile('WDSF Open ([a-zA-Z0-9 ]*) ((?:Standard)|(?:Latin))(?: *-.*)?') self._reWDSFCompetitionReversed = re.compile('WDSF Open ((?:Standard)|(?:Latin)) ([a-zA-Z0-9 ]*)(?: *-.*)?') + self._reGOCCompetition = re.compile('GOC ([a-zA-Z0-9 ]*) ((?:Standard)|(?:Latin))(?: (?:Rising Stars))?') self._reCleaningString = re.compile('[^a-z0-9-]') self._reDashes = re.compile('-+') @@ -46,7 +53,7 @@ class CompetitionParser: matcher = self._reName.match(h2.string) if matcher is None: self._l.error('Parsing of header "%s" failed.', h2) - raise ParsingFailedEception('Header could not be successfully parsed') + raise ParsingFailedException('Header could not be successfully parsed') self._partner = matcher.group(1) self._partnerin = matcher.group(2) @@ -54,38 +61,43 @@ class CompetitionParser: def parseDate(date): match = self._reDate.fullmatch(date) if match is None: - raise ParsingFailedEception('Cannot parse date %s in mail' % date) + raise ParsingFailedException('Cannot parse date %s in mail' % date) self._date = f'{match.group(3)}-{match.group(2)}-{match.group(1)}' def parseNumber(content): match = self._reNumber.fullmatch(content) if match is None: - raise ParsingFailedEception(f'Cannot parse the turnier number in field {content}') + raise ParsingFailedException(f'Cannot parse the turnier number in field {content}') self._number = match.group(1) def parseCompetition(competition): def parseDTVCompetition(): match = self._reCompetition.fullmatch(competition) if match is None: - raise ParsingFailedEception(f'Cannot parse the competition line {competition}') + raise ParsingFailedException(f'Cannot parse the competition line {competition}') self._group = match.group(1) self._class = match.group(2) - self._section = match.group(3) + self._section = self._reCompetitionSectionMap[match.group(3)] def parseWDSFCompetition(): def checkMatch(match): if match is None: - raise ParsingFailedEception(f'Cannot parse WDSF competition line') + raise ParsingFailedException(f'Cannot parse WDSF competition line') def parseForward(): match = self._reWDSFCompetition.fullmatch(competition.strip()) checkMatch(match) - return match.group(2), match.group(1) + return match.group(2), match.group(1), 'WDSF Open' def parseReverse(): match = self._reWDSFCompetitionReversed.fullmatch(competition.strip()) checkMatch(match) - return match.group(1), match.group(2).strip() + return match.group(1), match.group(2).strip(), 'WDSF Open' + + def parseGOC(): + match = self._reGOCCompetition.fullmatch(competition.strip()) + checkMatch(match) + return match.group(2), match.group(1), 'GOC Rising Stars' groupMap = { 'juvenile i': 'Kin', @@ -104,39 +116,39 @@ class CompetitionParser: 'standard': 'Std', 'latin': 'Lat', } - funs = [parseForward, parseReverse] + funs = [parseForward, parseReverse, parseGOC] for fun in funs: try: - sec, grp = fun() + sec, grp, cls_ = fun() self._group = groupMap.get(grp.lower(), grp) - self._class = 'WDSF Open' + self._class = cls_ self._section = sectionMap.get(sec.lower(), sec) return - except ParsingFailedEception: + except ParsingFailedException: pass - raise ParsingFailedEception('Neither forward not reversed parsing worked') + raise ParsingFailedException('Neither forward not reversed parsing worked') functions = [parseDTVCompetition, parseWDSFCompetition] for fun in functions: try: fun() return - except ParsingFailedEception: + except ParsingFailedException: pass - raise ParsingFailedEception(f'No more matchers for the competition line "{competition}" were left.') + raise ParsingFailedException(f'No more matchers for the competition line "{competition}" were left.') def parsePlace(place): match = self._rePlace.fullmatch(place) if match is None: - raise ParsingFailedEception(f'Cannot parse the place entry {place}') + raise ParsingFailedException(f'Cannot parse the place entry {place}') self._verein = match.group(1) self._ort = match.group(2) def parsePhone(phone): match = self._rePhone.fullmatch(phone) if match is None: - raise ParsingFailedEception(f'Cannot parse the phone line {phone}') + raise ParsingFailedException(f'Cannot parse the phone line {phone}') self._telefon = match.group(1) tds = table('td') diff --git a/scripts/read-competition-notification/run.sh b/scripts/read-competition-notification/run.sh index a347e8d..9483014 100755 --- a/scripts/read-competition-notification/run.sh +++ b/scripts/read-competition-notification/run.sh @@ -1,5 +1,7 @@ #!/bin/bash +source "$(dirname "$0")/venv/bin/activate" + export PYTHONPATH="$(dirname "$0"):$PYTHONPATH" python -m competitionNotificationReader "$@"