Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/schemas/clubs/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ClubPlayer(TransfermarktBaseModel):
id: str
name: str
position: str
image: Optional[str] = None
date_of_birth: Optional[date] = None
age: Optional[int] = None
nationality: list[str]
Expand Down
5 changes: 4 additions & 1 deletion app/services/clubs/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __parse_club_players(self) -> list[dict]:
players_ids = [extract_from_url(url) for url in self.get_list_by_xpath(Clubs.Players.URLS)]
players_names = self.get_list_by_xpath(Clubs.Players.NAMES)
players_positions = self.get_list_by_xpath(Clubs.Players.POSITIONS)
players_images = self.get_list_by_xpath(Clubs.Players.IMAGE) or ["None"] * len(players_ids)
players_dobs = [
safe_regex(dob_age, REGEX_DOB, "dob") for dob_age in self.get_list_by_xpath(Clubs.Players.DOB_AGE)
]
Expand Down Expand Up @@ -87,6 +88,7 @@ def __parse_club_players(self) -> list[dict]:
"id": idx,
"name": name,
"position": position,
"image": image,
"dateOfBirth": dob,
"age": age,
"nationality": nationality,
Expand All @@ -100,10 +102,11 @@ def __parse_club_players(self) -> list[dict]:
"marketValue": market_value,
"status": status,
}
for idx, name, position, dob, age, nationality, current_club, height, foot, joined_on, joined, signed_from, contract, market_value, status, in zip( # noqa: E501
for idx, name, position, image, dob, age, nationality, current_club, height, foot, joined_on, joined, signed_from, contract, market_value, status, in zip( # noqa: E501
players_ids,
players_names,
players_positions,
players_images,
players_dobs,
players_ages,
players_nationalities,
Expand Down
1 change: 1 addition & 0 deletions app/utils/xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class Players:
PAGE_INFOS = "//td[@class='posrela']"
NAMES = "//td[@class='posrela']//a//text()"
URLS = "//td[@class='hauptlink']//@href"
IMAGE = ".//img[contains(@class, 'bilderrahmen-fixed')]//@data-src"
POSITIONS = "//td[@class='posrela']//tr[2]//text()"
DOB_AGE = "//div[@id='yw1']//td[3]//text()"
NATIONALITIES = ".//img//@title"
Expand Down
1 change: 1 addition & 0 deletions tests/clubs/test_clubs_players.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_get_club_players(
"id": And(str, len_greater_than_0),
"name": And(str, len_greater_than_0),
"position": And(str, len_greater_than_0),
"image": Or(None, And(str, len_greater_than_0)),
"dateOfBirth": And(str, len_greater_than_0, regex_date_mmm_dd_yyyy),
"age": And(str, len_greater_than_0, regex_integer),
"nationality": And(list, len_greater_than_0),
Expand Down