Skip to content

Commit

Permalink
Rider number field added to Stage table parsing methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
themm1 committed Jun 18, 2023
1 parent 96dc5db commit 0ec407a
Show file tree
Hide file tree
Showing 12 changed files with 2,237 additions and 744 deletions.
25 changes: 20 additions & 5 deletions procyclingstats/stage_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def results(self, *args: str) -> List[Dict[str, Any]]:
- rider_name:
- rider_url:
- rider_number:
- team_name:
- team_url:
- rank: Rider's result in the stage.
Expand All @@ -255,6 +256,7 @@ def results(self, *args: str) -> List[Dict[str, Any]]:
available_fields = (
"rider_name",
"rider_url",
"rider_number",
"team_name",
"team_url",
"rank",
Expand Down Expand Up @@ -294,10 +296,15 @@ def results(self, *args: str) -> List[Dict[str, Any]]:
extra_fields.append("rider_url")
table_parser.parse(extra_fields)
table = join_tables(table, table_parser.table, "rider_url")
elif "nationality" in fields or "age" in fields:
elif "nationality" in fields or "age" in fields or \
"rider_number" in fields:
for row in table:
row['nationality'] = None
row['age'] = None
if "nationality" in fields:
row['nationality'] = None
if "age" in fields:
row['age'] = None
if "rider_number" in fields:
row['rider_number'] = None
# remove rider_url from table if isn't needed
if "rider_url" not in fields:
for row in table:
Expand All @@ -319,6 +326,7 @@ def gc(self, *args: str) -> List[Dict[str, Any]]: \
- rider_name:
- rider_url:
- rider_number:
- team_name:
- team_url:
- rank: Rider's GC rank after the stage.
Expand All @@ -336,6 +344,7 @@ def gc(self, *args: str) -> List[Dict[str, Any]]: \
available_fields = (
"rider_name",
"rider_url",
"rider_number",
"team_name",
"team_url",
"rank",
Expand Down Expand Up @@ -366,6 +375,7 @@ def points(self, *args: str) -> List[Dict[str, Any]]:
- rider_name:
- rider_url:
- rider_number:
- team_name:
- team_url:
- rank: Rider's points classif. rank after the stage.
Expand All @@ -382,6 +392,7 @@ def points(self, *args: str) -> List[Dict[str, Any]]:
available_fields = (
"rider_name",
"rider_url",
"rider_number",
"team_name",
"team_url",
"rank",
Expand Down Expand Up @@ -411,6 +422,7 @@ def kom(self, *args: str) -> List[Dict[str, Any]]:
- rider_name:
- rider_url:
- rider_number:
- team_name:
- team_url:
- rank: Rider's KOM classif. rank after the stage.
Expand All @@ -427,6 +439,7 @@ def kom(self, *args: str) -> List[Dict[str, Any]]:
available_fields = (
"rider_name",
"rider_url",
"rider_number",
"team_name",
"team_url",
"rank",
Expand Down Expand Up @@ -456,6 +469,7 @@ def youth(self, *args: str) -> List[Dict[str, Any]]:
- rider_name:
- rider_url:
- rider_number:
- team_name:
- team_url:
- rank: Rider's youth classif. rank after the stage.
Expand All @@ -472,6 +486,7 @@ def youth(self, *args: str) -> List[Dict[str, Any]]:
available_fields = (
"rider_name",
"rider_url",
"rider_number",
"team_name",
"team_url",
"rank",
Expand Down Expand Up @@ -566,8 +581,8 @@ def _ttt_results(results_table_html: Node,
:param results_table_html: TTT results table HTML.
:param fields: Fields that returned table should have. Available are
all `results` table fields with the exception of age and
nationality.
all `results` table fields with the exception of age,
nationality and rider_number.
:return: Table with wanted fields.
"""
team_fields = [
Expand Down
6 changes: 6 additions & 0 deletions procyclingstats/table_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def parse(self, fields: Union[List[str], Tuple[str, ...]]) -> None:
- bonus
- profile_icon
- season
- rider_number
:fields options for tables with a header:
- rank
Expand Down Expand Up @@ -283,6 +284,11 @@ def season(self) -> List[Optional[int]]:
else:
seasons.append(None)
return seasons

def rider_number(self) -> List[Optional[int]]:
bibs_elements = self.html_table.css(".bibs")
return [int(bib_e.text()) if bib_e.text().isnumeric() else None \
for bib_e in bibs_elements]

def rank(self) -> List[Optional[int]]:
possible_columns = ["Rnk", "pos", "Result", "#"]
Expand Down
Loading

0 comments on commit 0ec407a

Please sign in to comment.