Fix parsing of mails with WDSF content
This commit is contained in:
parent
feb7810367
commit
8ed2812e28
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
dateCompetition: 2024-04-14
|
||||||
|
partner: "Baal, David"
|
||||||
|
partnerin: "Ralko, Valeriia"
|
||||||
|
verein: "Max-Schmeling-Halle"
|
||||||
|
ort: "Berlin"
|
||||||
|
telefon: "+49 30 4404 8404"
|
||||||
|
gruppe: "Jug"
|
||||||
|
klasse: "WDSF Open"
|
||||||
|
sektion: "Std"
|
||||||
|
titel: "Berlin Dance Festival 2024"
|
||||||
|
nummer: 117902
|
||||||
|
---
|
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
dateCompetition: 2024-05-12
|
||||||
|
partner: "Baal, David"
|
||||||
|
partnerin: "Ralko, Valeriia"
|
||||||
|
verein: "Eissporthalle"
|
||||||
|
ort: "Frankfurt am Main"
|
||||||
|
telefon: "017645998403"
|
||||||
|
gruppe: "Jug"
|
||||||
|
klasse: "WDSF Open"
|
||||||
|
sektion: "Std"
|
||||||
|
titel: "Hessen tanzt"
|
||||||
|
nummer: 114699
|
||||||
|
---
|
@ -28,9 +28,11 @@ class CompetitionParser:
|
|||||||
self._reName = re.compile('Neue Meldung für (.*) / (.*)!')
|
self._reName = re.compile('Neue Meldung für (.*) / (.*)!')
|
||||||
self._reDate = re.compile('([0-9]+)\.([0-9]+)\.([0-9]+)')
|
self._reDate = re.compile('([0-9]+)\.([0-9]+)\.([0-9]+)')
|
||||||
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))')
|
||||||
|
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._reCleaningString = re.compile('[^a-z0-9-]')
|
self._reCleaningString = re.compile('[^a-z0-9-]')
|
||||||
self._reDashes = re.compile('-+')
|
self._reDashes = re.compile('-+')
|
||||||
@ -62,12 +64,67 @@ class CompetitionParser:
|
|||||||
self._number = match.group(1)
|
self._number = match.group(1)
|
||||||
|
|
||||||
def parseCompetition(competition):
|
def parseCompetition(competition):
|
||||||
match = self._reCompetition.fullmatch(competition)
|
def parseDTVCompetition():
|
||||||
if match is None:
|
match = self._reCompetition.fullmatch(competition)
|
||||||
raise ParsingFailedEception(f'Cannot parse the competition line {competition}')
|
if match is None:
|
||||||
self._group = match.group(1)
|
raise ParsingFailedEception(f'Cannot parse the competition line {competition}')
|
||||||
self._class = match.group(2)
|
self._group = match.group(1)
|
||||||
self._section = match.group(3)
|
self._class = match.group(2)
|
||||||
|
self._section = match.group(3)
|
||||||
|
|
||||||
|
def parseWDSFCompetition():
|
||||||
|
def checkMatch(match):
|
||||||
|
if match is None:
|
||||||
|
raise ParsingFailedEception(f'Cannot parse WDSF competition line')
|
||||||
|
|
||||||
|
def parseForward():
|
||||||
|
match = self._reWDSFCompetition.fullmatch(competition.strip())
|
||||||
|
checkMatch(match)
|
||||||
|
return match.group(2), match.group(1)
|
||||||
|
|
||||||
|
def parseReverse():
|
||||||
|
match = self._reWDSFCompetitionReversed.fullmatch(competition.strip())
|
||||||
|
checkMatch(match)
|
||||||
|
return match.group(1), match.group(2).strip()
|
||||||
|
|
||||||
|
groupMap = {
|
||||||
|
'juvenile i': 'Kin',
|
||||||
|
'juvenile ii': 'Kin',
|
||||||
|
'junior i': 'Jun 1',
|
||||||
|
'junior ii': 'Jun 2',
|
||||||
|
'youth': 'Jug',
|
||||||
|
'adult': 'Hgr',
|
||||||
|
'senior i': 'Mas I',
|
||||||
|
'senior ii': 'Mas II',
|
||||||
|
'senior iii': 'Mas III',
|
||||||
|
'senior iv': 'Mas IV',
|
||||||
|
'senior v': 'Mas V',
|
||||||
|
}
|
||||||
|
sectionMap = {
|
||||||
|
'standard': 'Std',
|
||||||
|
'latin': 'Lat',
|
||||||
|
}
|
||||||
|
funs = [parseForward, parseReverse]
|
||||||
|
for fun in funs:
|
||||||
|
try:
|
||||||
|
sec, grp = fun()
|
||||||
|
self._group = groupMap.get(grp.lower(), grp)
|
||||||
|
self._class = 'WDSF Open'
|
||||||
|
self._section = sectionMap.get(sec.lower(), sec)
|
||||||
|
return
|
||||||
|
except ParsingFailedEception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
raise ParsingFailedEception('Neither forward not reversed parsing worked')
|
||||||
|
|
||||||
|
functions = [parseDTVCompetition, parseWDSFCompetition]
|
||||||
|
for fun in functions:
|
||||||
|
try:
|
||||||
|
fun()
|
||||||
|
return
|
||||||
|
except ParsingFailedEception:
|
||||||
|
pass
|
||||||
|
raise ParsingFailedEception(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)
|
||||||
|
Loading…
Reference in New Issue
Block a user