Fixed some code styings
This commit is contained in:
parent
533f3ef237
commit
4bc626b163
@ -43,7 +43,10 @@ class HtmlParser:
|
|||||||
|
|
||||||
match = re.compile('.*?OT, Solos (.*?)(?: ".*")?').fullmatch(title)
|
match = re.compile('.*?OT, Solos (.*?)(?: ".*")?').fullmatch(title)
|
||||||
if match is None:
|
if match is None:
|
||||||
self.l.debug('Parsing HTML page title "%s" as OT failed. Falling back to legacy ETW.', title)
|
self.l.debug(
|
||||||
|
'Parsing HTML page title "%s" as OT failed. Falling back to legacy ETW.',
|
||||||
|
title,
|
||||||
|
)
|
||||||
match = re.compile('.*?ETW, Solos (.*?)(?: ".*")?').fullmatch(title)
|
match = re.compile('.*?ETW, Solos (.*?)(?: ".*")?').fullmatch(title)
|
||||||
if match is None:
|
if match is None:
|
||||||
self.l.info(
|
self.l.info(
|
||||||
@ -65,11 +68,14 @@ class HtmlParser:
|
|||||||
participants = {}
|
participants = {}
|
||||||
|
|
||||||
nameRegex = re.compile("(.*) \\(([0-9]+)\\)")
|
nameRegex = re.compile("(.*) \\(([0-9]+)\\)")
|
||||||
|
|
||||||
def __parseNameAndId(string: str, tds) -> tuple[str, str]:
|
def __parseNameAndId(string: str, tds) -> tuple[str, str]:
|
||||||
match = nameRegex.fullmatch(string)
|
match = nameRegex.fullmatch(string)
|
||||||
if match is None:
|
if match is None:
|
||||||
self.l.error("Could not match %s to regex search pattern", str(tds))
|
self.l.error("Could not match %s to regex search pattern", str(tds))
|
||||||
raise CannotParseRowException(f"Could not match {tds} to regex search pattern for 'name (id)'")
|
raise CannotParseRowException(
|
||||||
|
f"Could not match {tds} to regex search pattern for 'name (id)'"
|
||||||
|
)
|
||||||
name = match.group(1)
|
name = match.group(1)
|
||||||
number = match.group(2)
|
number = match.group(2)
|
||||||
return name, number
|
return name, number
|
||||||
@ -78,31 +84,33 @@ class HtmlParser:
|
|||||||
def parseRow(row):
|
def parseRow(row):
|
||||||
for parser in parsers:
|
for parser in parsers:
|
||||||
try:
|
try:
|
||||||
parser(row('td'))
|
parser(row("td"))
|
||||||
return
|
return
|
||||||
except CannotParseRowException:
|
except CannotParseRowException:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# No parser was found if we get here.
|
# No parser was found if we get here.
|
||||||
self.l.error('Cannot parse row in table.')
|
self.l.error("Cannot parse row in table.")
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
parseRow(row)
|
parseRow(row)
|
||||||
|
|
||||||
def __ensureLength(tds, length):
|
def __ensureLength(tds, length):
|
||||||
if len(tds) != length:
|
if len(tds) != length:
|
||||||
raise CannotParseRowException('The row has %d entries but %d are expected.' % (len(tds), length))
|
raise CannotParseRowException(
|
||||||
|
"The row has %d entries but %d are expected." % (len(tds), length)
|
||||||
|
)
|
||||||
|
|
||||||
def __parseFormationRowGeneric(tds, finalist):
|
def __parseFormationRowGeneric(tds, finalist):
|
||||||
__ensureLength(tds, 2)
|
__ensureLength(tds, 2)
|
||||||
|
|
||||||
place = tds[0].contents[0]
|
place = tds[0].contents[0]
|
||||||
name, number = __parseNameAndId(tds[1].contents[0], tds)
|
name, number = __parseNameAndId(tds[1].contents[0], tds)
|
||||||
|
|
||||||
participant = HtmlParticipant(name, number)
|
participant = HtmlParticipant(name, number)
|
||||||
participant.finalist = finalist
|
participant.finalist = finalist
|
||||||
participant.club = ''
|
participant.club = ""
|
||||||
participants[participant] = place
|
participants[participant] = place
|
||||||
|
|
||||||
def __parseFirstTable(table):
|
def __parseFirstTable(table):
|
||||||
roundName = table.tr.td.contents[0]
|
roundName = table.tr.td.contents[0]
|
||||||
@ -124,10 +132,16 @@ class HtmlParser:
|
|||||||
participant = HtmlParticipant(name, number)
|
participant = HtmlParticipant(name, number)
|
||||||
participant.finalist = True
|
participant.finalist = True
|
||||||
participant.club = tdClub.contents[0]
|
participant.club = tdClub.contents[0]
|
||||||
|
|
||||||
participants[participant] = place
|
participants[participant] = place
|
||||||
|
|
||||||
__parseRows(table.find_all("tr")[2:], [__parsePairRow, __parseFormationRow,])
|
__parseRows(
|
||||||
|
table.find_all("tr")[2:],
|
||||||
|
[
|
||||||
|
__parsePairRow,
|
||||||
|
__parseFormationRow,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def __parseRemainingTables(tables):
|
def __parseRemainingTables(tables):
|
||||||
|
|
||||||
@ -143,40 +157,54 @@ class HtmlParser:
|
|||||||
participant = HtmlParticipant(name, number)
|
participant = HtmlParticipant(name, number)
|
||||||
participant.finalist = False
|
participant.finalist = False
|
||||||
participant.club = tds[2].contents[0]
|
participant.club = tds[2].contents[0]
|
||||||
|
|
||||||
participants[participant] = place
|
participants[participant] = place
|
||||||
|
|
||||||
def __parseSeparatorRow(tds):
|
def __parseSeparatorRow(tds):
|
||||||
__ensureLength(tds, 1)
|
__ensureLength(tds, 1)
|
||||||
if len(list(tds[0].stripped_strings)) == 0:
|
if len(list(tds[0].stripped_strings)) == 0:
|
||||||
return
|
return
|
||||||
raise CannotParseRowException('No empty string')
|
raise CannotParseRowException("No empty string")
|
||||||
|
|
||||||
regexZwischenRunde = re.compile('[1-9]\. Zwischenrunde')
|
regexZwischenRunde = re.compile("[1-9]\. Zwischenrunde")
|
||||||
|
|
||||||
def __parseRoundHeading(tds):
|
def __parseRoundHeading(tds):
|
||||||
__ensureLength(tds, 1)
|
__ensureLength(tds, 1)
|
||||||
s = ''.join(tds[0].stripped_strings)
|
s = "".join(tds[0].stripped_strings)
|
||||||
if s.startswith('Vorrunde'):
|
if s.startswith("Vorrunde"):
|
||||||
return
|
return
|
||||||
if regexZwischenRunde.match(s) is not None:
|
if regexZwischenRunde.match(s) is not None:
|
||||||
return
|
return
|
||||||
raise CannotParseRowException('Kein Header einer Runde gefunden.')
|
raise CannotParseRowException("Kein Header einer Runde gefunden.")
|
||||||
|
|
||||||
def __parseAllSolosQualifiedFormation(tds):
|
def __parseAllSolosQualifiedFormation(tds):
|
||||||
__ensureLength(tds, 2)
|
__ensureLength(tds, 2)
|
||||||
if tds[1].contents[0].startswith("Alle Starter weiter genommen."):
|
if tds[1].contents[0].startswith("Alle Starter weiter genommen."):
|
||||||
return
|
return
|
||||||
raise CannotParseRowException('Not found the text "Alle Starter weiter genommen"')
|
raise CannotParseRowException(
|
||||||
|
'Not found the text "Alle Starter weiter genommen"'
|
||||||
|
)
|
||||||
|
|
||||||
def __parseAllSolosQualifiedPair(tds):
|
def __parseAllSolosQualifiedPair(tds):
|
||||||
__ensureLength(tds, 3)
|
__ensureLength(tds, 3)
|
||||||
if tds[1].contents[0].startswith("Alle Mannschaften weiter genommen."):
|
if tds[1].contents[0].startswith("Alle Mannschaften weiter genommen."):
|
||||||
return
|
return
|
||||||
raise CannotParseRowException('Not found the text "Alle Mannschaften weiter genommen"')
|
raise CannotParseRowException(
|
||||||
|
'Not found the text "Alle Mannschaften weiter genommen"'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
for table in tables:
|
for table in tables:
|
||||||
__parseRows(table.find_all("tr"), [__parseAllSolosQualifiedFormation, __parseAllSolosQualifiedPair, __parsePairRow, __parseFormationRow, __parseSeparatorRow, __parseRoundHeading])
|
__parseRows(
|
||||||
|
table.find_all("tr"),
|
||||||
|
[
|
||||||
|
__parseAllSolosQualifiedFormation,
|
||||||
|
__parseAllSolosQualifiedPair,
|
||||||
|
__parsePairRow,
|
||||||
|
__parseFormationRow,
|
||||||
|
__parseSeparatorRow,
|
||||||
|
__parseRoundHeading,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
tables = self.soup.find("div", class_="extract").find_all("table")
|
tables = self.soup.find("div", class_="extract").find_all("table")
|
||||||
|
|
||||||
|
@ -132,10 +132,10 @@ class ConsoleOutputter(AbstractOutputter):
|
|||||||
|
|
||||||
mappedResults = map(mapResultColumn, results)
|
mappedResults = map(mapResultColumn, results)
|
||||||
|
|
||||||
participantName = f'{participant.name} ({participant.id})'
|
participantName = f"{participant.name} ({participant.id})"
|
||||||
if participant.club is not None:
|
if participant.club is not None:
|
||||||
participantName = f'{participantName}, {participant.club}'
|
participantName = f"{participantName}, {participant.club}"
|
||||||
|
|
||||||
tableRow = [f"{participantName}"] + list(mappedResults)
|
tableRow = [f"{participantName}"] + list(mappedResults)
|
||||||
tableData.append(tableRow)
|
tableData.append(tableRow)
|
||||||
|
|
||||||
|
@ -1,53 +1,51 @@
|
|||||||
|
|
||||||
.tab-summary {
|
.tab-summary {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab-summary tr:nth-of-type(even) {
|
.tab-summary tr:nth-of-type(even) {
|
||||||
background-color: cyan;
|
background-color: cyan;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab-summary td {
|
.tab-summary td {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab-summary td .competition-place {
|
.tab-summary td .competition-place {
|
||||||
font-size: smaller;
|
font-size: smaller;
|
||||||
font-weight: 300;
|
font-weight: 300;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab-summary .no-finalist {
|
.tab-summary .no-finalist {
|
||||||
color: gray;
|
color: gray;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab-summary .no-finalist-dance {
|
.tab-summary .no-finalist-dance {
|
||||||
color: gray;
|
color: gray;
|
||||||
text-decoration-style: solid;
|
text-decoration-style: solid;
|
||||||
text-decoration-line: line-through;
|
text-decoration-line: line-through;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media print {
|
@media print {
|
||||||
@page {
|
@page {
|
||||||
size: landscape;
|
size: landscape;
|
||||||
}
|
}
|
||||||
@page portrait {
|
@page portrait {
|
||||||
size: portrait;
|
size: portrait;
|
||||||
}
|
}
|
||||||
/* body {
|
/* body {
|
||||||
size: landscape;
|
size: landscape;
|
||||||
page-orientation: rotate-right;
|
page-orientation: rotate-right;
|
||||||
} */
|
} */
|
||||||
|
|
||||||
.section,
|
.section,
|
||||||
.section table tr,
|
.section table tr,
|
||||||
.section table td
|
.section table td {
|
||||||
{
|
page-break-inside: avoid;
|
||||||
page-break-inside: avoid;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.tab-summary .no-finalist {
|
.tab-summary .no-finalist {
|
||||||
color: gray;
|
color: gray;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,6 @@ class SingleParticipantResult:
|
|||||||
|
|
||||||
def getNativePlace(self) -> str:
|
def getNativePlace(self) -> str:
|
||||||
return str(self.nativePlace)
|
return str(self.nativePlace)
|
||||||
|
|
||||||
def isCombinedGroup(self) -> bool:
|
def isCombinedGroup(self) -> bool:
|
||||||
return isinstance(self.competitionGroup, solo_turnier.group.CombinedGroup)
|
return isinstance(self.competitionGroup, solo_turnier.group.CombinedGroup)
|
||||||
|
Loading…
Reference in New Issue
Block a user