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)
|
||||
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)
|
||||
if match is None:
|
||||
self.l.info(
|
||||
@ -65,11 +68,14 @@ class HtmlParser:
|
||||
participants = {}
|
||||
|
||||
nameRegex = re.compile("(.*) \\(([0-9]+)\\)")
|
||||
|
||||
def __parseNameAndId(string: str, tds) -> tuple[str, str]:
|
||||
match = nameRegex.fullmatch(string)
|
||||
if match is None:
|
||||
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)
|
||||
number = match.group(2)
|
||||
return name, number
|
||||
@ -78,31 +84,33 @@ class HtmlParser:
|
||||
def parseRow(row):
|
||||
for parser in parsers:
|
||||
try:
|
||||
parser(row('td'))
|
||||
parser(row("td"))
|
||||
return
|
||||
except CannotParseRowException:
|
||||
pass
|
||||
|
||||
# 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:
|
||||
parseRow(row)
|
||||
|
||||
def __ensureLength(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):
|
||||
__ensureLength(tds, 2)
|
||||
__ensureLength(tds, 2)
|
||||
|
||||
place = tds[0].contents[0]
|
||||
name, number = __parseNameAndId(tds[1].contents[0], tds)
|
||||
place = tds[0].contents[0]
|
||||
name, number = __parseNameAndId(tds[1].contents[0], tds)
|
||||
|
||||
participant = HtmlParticipant(name, number)
|
||||
participant.finalist = finalist
|
||||
participant.club = ''
|
||||
participants[participant] = place
|
||||
participant = HtmlParticipant(name, number)
|
||||
participant.finalist = finalist
|
||||
participant.club = ""
|
||||
participants[participant] = place
|
||||
|
||||
def __parseFirstTable(table):
|
||||
roundName = table.tr.td.contents[0]
|
||||
@ -127,7 +135,13 @@ class HtmlParser:
|
||||
|
||||
participants[participant] = place
|
||||
|
||||
__parseRows(table.find_all("tr")[2:], [__parsePairRow, __parseFormationRow,])
|
||||
__parseRows(
|
||||
table.find_all("tr")[2:],
|
||||
[
|
||||
__parsePairRow,
|
||||
__parseFormationRow,
|
||||
],
|
||||
)
|
||||
|
||||
def __parseRemainingTables(tables):
|
||||
|
||||
@ -150,33 +164,47 @@ class HtmlParser:
|
||||
__ensureLength(tds, 1)
|
||||
if len(list(tds[0].stripped_strings)) == 0:
|
||||
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):
|
||||
__ensureLength(tds, 1)
|
||||
s = ''.join(tds[0].stripped_strings)
|
||||
if s.startswith('Vorrunde'):
|
||||
s = "".join(tds[0].stripped_strings)
|
||||
if s.startswith("Vorrunde"):
|
||||
return
|
||||
if regexZwischenRunde.match(s) is not None:
|
||||
return
|
||||
raise CannotParseRowException('Kein Header einer Runde gefunden.')
|
||||
raise CannotParseRowException("Kein Header einer Runde gefunden.")
|
||||
|
||||
def __parseAllSolosQualifiedFormation(tds):
|
||||
__ensureLength(tds, 2)
|
||||
if tds[1].contents[0].startswith("Alle Starter weiter genommen."):
|
||||
return
|
||||
raise CannotParseRowException('Not found the text "Alle Starter weiter genommen"')
|
||||
raise CannotParseRowException(
|
||||
'Not found the text "Alle Starter weiter genommen"'
|
||||
)
|
||||
|
||||
def __parseAllSolosQualifiedPair(tds):
|
||||
__ensureLength(tds, 3)
|
||||
if tds[1].contents[0].startswith("Alle Mannschaften weiter genommen."):
|
||||
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:
|
||||
__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")
|
||||
|
||||
|
@ -132,9 +132,9 @@ class ConsoleOutputter(AbstractOutputter):
|
||||
|
||||
mappedResults = map(mapResultColumn, results)
|
||||
|
||||
participantName = f'{participant.name} ({participant.id})'
|
||||
participantName = f"{participant.name} ({participant.id})"
|
||||
if participant.club is not None:
|
||||
participantName = f'{participantName}, {participant.club}'
|
||||
participantName = f"{participantName}, {participant.club}"
|
||||
|
||||
tableRow = [f"{participantName}"] + list(mappedResults)
|
||||
tableData.append(tableRow)
|
||||
|
@ -1,53 +1,51 @@
|
||||
|
||||
.tab-summary {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.tab-summary tr:nth-of-type(even) {
|
||||
background-color: cyan;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.tab-summary td {
|
||||
text-align: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.tab-summary td .competition-place {
|
||||
font-size: smaller;
|
||||
font-weight: 300;
|
||||
font-style: italic;
|
||||
font-size: smaller;
|
||||
font-weight: 300;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.tab-summary .no-finalist {
|
||||
color: gray;
|
||||
color: gray;
|
||||
}
|
||||
|
||||
.tab-summary .no-finalist-dance {
|
||||
color: gray;
|
||||
text-decoration-style: solid;
|
||||
text-decoration-line: line-through;
|
||||
color: gray;
|
||||
text-decoration-style: solid;
|
||||
text-decoration-line: line-through;
|
||||
}
|
||||
|
||||
@media print {
|
||||
@page {
|
||||
size: landscape;
|
||||
}
|
||||
@page portrait {
|
||||
size: portrait;
|
||||
}
|
||||
/* body {
|
||||
@page {
|
||||
size: landscape;
|
||||
}
|
||||
@page portrait {
|
||||
size: portrait;
|
||||
}
|
||||
/* body {
|
||||
size: landscape;
|
||||
page-orientation: rotate-right;
|
||||
} */
|
||||
|
||||
.section,
|
||||
.section table tr,
|
||||
.section table td
|
||||
{
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
.section,
|
||||
.section table tr,
|
||||
.section table td {
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
.tab-summary .no-finalist {
|
||||
color: gray;
|
||||
}
|
||||
.tab-summary .no-finalist {
|
||||
color: gray;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user