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,20 +84,22 @@ 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)
|
||||
@ -101,7 +109,7 @@ class HtmlParser:
|
||||
|
||||
participant = HtmlParticipant(name, number)
|
||||
participant.finalist = finalist
|
||||
participant.club = ''
|
||||
participant.club = ""
|
||||
participants[participant] = place
|
||||
|
||||
def __parseFirstTable(table):
|
||||
@ -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,4 +1,3 @@
|
||||
|
||||
.tab-summary {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
@ -42,8 +41,7 @@
|
||||
|
||||
.section,
|
||||
.section table tr,
|
||||
.section table td
|
||||
{
|
||||
.section table td {
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user