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,20 +84,22 @@ 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)
|
||||||
@ -101,7 +109,7 @@ class HtmlParser:
|
|||||||
|
|
||||||
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):
|
||||||
@ -127,7 +135,13 @@ class HtmlParser:
|
|||||||
|
|
||||||
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):
|
||||||
|
|
||||||
@ -150,33 +164,47 @@ class HtmlParser:
|
|||||||
__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,9 +132,9 @@ 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,4 +1,3 @@
|
|||||||
|
|
||||||
.tab-summary {
|
.tab-summary {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
@ -42,8 +41,7 @@
|
|||||||
|
|
||||||
.section,
|
.section,
|
||||||
.section table tr,
|
.section table tr,
|
||||||
.section table td
|
.section table td {
|
||||||
{
|
|
||||||
page-break-inside: avoid;
|
page-break-inside: avoid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user