Skip to content

Commit

Permalink
Add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeall committed Dec 14, 2023
1 parent 7a94286 commit 206962a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/services/players/injuries.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,37 @@

@dataclass
class TransfermarktPlayerInjuries(TransfermarktBase):
"""
Represents a service for retrieving and parsing the injury history of a football player on Transfermarkt.
Args:
player_id (str): The unique identifier of the player.
page_number (int): The page number of the player's injury history.
Attributes:
URL (str): The URL to fetch the player's injury history data.
"""

player_id: str = None
URL: str = "https://www.transfermarkt.com/player/verletzungen/spieler/{player_id}/plus/1/page/{page_number}"
page_number: int = 1

def __post_init__(self):
"""Initialize the TransfermarktPlayerInjuries class."""
self.URL = self.URL.format(player_id=self.player_id, page_number=self.page_number)
self.page = self.request_url_page()
self.raise_exception_if_not_found(xpath=Players.Profile.URL)

def __parse_player_injuries(self) -> Optional[List[dict]]:
"""
Parse the injury history of a football player from the retrieved data.
Returns:
list: A list of dictionaries, where each dictionary represents an injury in the
player's injury history. Each dictionary contains keys 'season', 'injury', 'from',
'until', 'days', 'gamesMissed', and 'gamesMissedClubs' with their respective values.
"""
injuries: ElementTree = self.page.xpath(Players.Injuries.RESULTS)
player_injuries = []

Expand Down Expand Up @@ -48,6 +69,14 @@ def __parse_player_injuries(self) -> Optional[List[dict]]:
return player_injuries

def get_player_injuries(self) -> dict:
"""
Retrieve and parse the injury history of a football player.
Returns:
dict: A dictionary containing the player's unique identifier, current page number,
last page number, and injury history.
"""
self.response["id"] = self.player_id
self.response["pageNumber"] = self.page_number
self.response["lastPageNumber"] = self.get_last_page_number()
Expand Down

0 comments on commit 206962a

Please sign in to comment.