Fix parsinf for some ESV mails
This commit is contained in:
parent
6ccd4fa0c8
commit
ff88ca056f
@ -4,7 +4,7 @@ import re
|
|||||||
import os
|
import os
|
||||||
import jinja2
|
import jinja2
|
||||||
|
|
||||||
class ParsingFailedEception(Exception):
|
class ParsingFailedException(Exception):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
@ -30,9 +30,16 @@ class CompetitionParser:
|
|||||||
self._reNumber = re.compile('Turnier: ([0-9]+)')
|
self._reNumber = re.compile('Turnier: ([0-9]+)')
|
||||||
self._rePhone = re.compile('Telefon: (\\+?[0-9 /-]+)')
|
self._rePhone = re.compile('Telefon: (\\+?[0-9 /-]+)')
|
||||||
self._rePlace = re.compile('Ort: (.*), (.*)')
|
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._reWDSFCompetition = re.compile('WDSF Open ([a-zA-Z0-9 ]*) ((?:Standard)|(?:Latin))(?: *-.*)?')
|
||||||
self._reWDSFCompetitionReversed = re.compile('WDSF Open ((?:Standard)|(?:Latin)) ([a-zA-Z0-9 ]*)(?: *-.*)?')
|
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._reCleaningString = re.compile('[^a-z0-9-]')
|
||||||
self._reDashes = re.compile('-+')
|
self._reDashes = re.compile('-+')
|
||||||
@ -46,7 +53,7 @@ class CompetitionParser:
|
|||||||
matcher = self._reName.match(h2.string)
|
matcher = self._reName.match(h2.string)
|
||||||
if matcher is None:
|
if matcher is None:
|
||||||
self._l.error('Parsing of header "%s" failed.', h2)
|
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._partner = matcher.group(1)
|
||||||
self._partnerin = matcher.group(2)
|
self._partnerin = matcher.group(2)
|
||||||
|
|
||||||
@ -54,38 +61,43 @@ class CompetitionParser:
|
|||||||
def parseDate(date):
|
def parseDate(date):
|
||||||
match = self._reDate.fullmatch(date)
|
match = self._reDate.fullmatch(date)
|
||||||
if match is None:
|
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)}'
|
self._date = f'{match.group(3)}-{match.group(2)}-{match.group(1)}'
|
||||||
|
|
||||||
def parseNumber(content):
|
def parseNumber(content):
|
||||||
match = self._reNumber.fullmatch(content)
|
match = self._reNumber.fullmatch(content)
|
||||||
if match is None:
|
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)
|
self._number = match.group(1)
|
||||||
|
|
||||||
def parseCompetition(competition):
|
def parseCompetition(competition):
|
||||||
def parseDTVCompetition():
|
def parseDTVCompetition():
|
||||||
match = self._reCompetition.fullmatch(competition)
|
match = self._reCompetition.fullmatch(competition)
|
||||||
if match is None:
|
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._group = match.group(1)
|
||||||
self._class = match.group(2)
|
self._class = match.group(2)
|
||||||
self._section = match.group(3)
|
self._section = self._reCompetitionSectionMap[match.group(3)]
|
||||||
|
|
||||||
def parseWDSFCompetition():
|
def parseWDSFCompetition():
|
||||||
def checkMatch(match):
|
def checkMatch(match):
|
||||||
if match is None:
|
if match is None:
|
||||||
raise ParsingFailedEception(f'Cannot parse WDSF competition line')
|
raise ParsingFailedException(f'Cannot parse WDSF competition line')
|
||||||
|
|
||||||
def parseForward():
|
def parseForward():
|
||||||
match = self._reWDSFCompetition.fullmatch(competition.strip())
|
match = self._reWDSFCompetition.fullmatch(competition.strip())
|
||||||
checkMatch(match)
|
checkMatch(match)
|
||||||
return match.group(2), match.group(1)
|
return match.group(2), match.group(1), 'WDSF Open'
|
||||||
|
|
||||||
def parseReverse():
|
def parseReverse():
|
||||||
match = self._reWDSFCompetitionReversed.fullmatch(competition.strip())
|
match = self._reWDSFCompetitionReversed.fullmatch(competition.strip())
|
||||||
checkMatch(match)
|
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 = {
|
groupMap = {
|
||||||
'juvenile i': 'Kin',
|
'juvenile i': 'Kin',
|
||||||
@ -104,39 +116,39 @@ class CompetitionParser:
|
|||||||
'standard': 'Std',
|
'standard': 'Std',
|
||||||
'latin': 'Lat',
|
'latin': 'Lat',
|
||||||
}
|
}
|
||||||
funs = [parseForward, parseReverse]
|
funs = [parseForward, parseReverse, parseGOC]
|
||||||
for fun in funs:
|
for fun in funs:
|
||||||
try:
|
try:
|
||||||
sec, grp = fun()
|
sec, grp, cls_ = fun()
|
||||||
self._group = groupMap.get(grp.lower(), grp)
|
self._group = groupMap.get(grp.lower(), grp)
|
||||||
self._class = 'WDSF Open'
|
self._class = cls_
|
||||||
self._section = sectionMap.get(sec.lower(), sec)
|
self._section = sectionMap.get(sec.lower(), sec)
|
||||||
return
|
return
|
||||||
except ParsingFailedEception:
|
except ParsingFailedException:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
raise ParsingFailedEception('Neither forward not reversed parsing worked')
|
raise ParsingFailedException('Neither forward not reversed parsing worked')
|
||||||
|
|
||||||
functions = [parseDTVCompetition, parseWDSFCompetition]
|
functions = [parseDTVCompetition, parseWDSFCompetition]
|
||||||
for fun in functions:
|
for fun in functions:
|
||||||
try:
|
try:
|
||||||
fun()
|
fun()
|
||||||
return
|
return
|
||||||
except ParsingFailedEception:
|
except ParsingFailedException:
|
||||||
pass
|
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):
|
def parsePlace(place):
|
||||||
match = self._rePlace.fullmatch(place)
|
match = self._rePlace.fullmatch(place)
|
||||||
if match is None:
|
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._verein = match.group(1)
|
||||||
self._ort = match.group(2)
|
self._ort = match.group(2)
|
||||||
|
|
||||||
def parsePhone(phone):
|
def parsePhone(phone):
|
||||||
match = self._rePhone.fullmatch(phone)
|
match = self._rePhone.fullmatch(phone)
|
||||||
if match is None:
|
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)
|
self._telefon = match.group(1)
|
||||||
|
|
||||||
tds = table('td')
|
tds = table('td')
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
source "$(dirname "$0")/venv/bin/activate"
|
||||||
|
|
||||||
export PYTHONPATH="$(dirname "$0"):$PYTHONPATH"
|
export PYTHONPATH="$(dirname "$0"):$PYTHONPATH"
|
||||||
|
|
||||||
python -m competitionNotificationReader "$@"
|
python -m competitionNotificationReader "$@"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user