Skip to content

Commit

Permalink
Fix Joined On info in Clubs/Players endpoint (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeall authored Jun 16, 2024
1 parent 3555d4f commit 64079fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions app/services/clubs/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __update_season_id(self):
def __update_past_flag(self) -> None:
"""Check if the season is the current or if it's a past one and update the flag accordingly."""
self.past = "Current club" in self.get_list_by_xpath(Clubs.Players.PAST_FLAG)
print(f"{self.past=}")

def __parse_club_players(self) -> list[dict]:
"""
Expand All @@ -51,6 +52,9 @@ def __parse_club_players(self) -> list[dict]:
page_players_signed_from = self.page.xpath(
Clubs.Players.Past.PAGE_SIGNED_FROM if self.past else Clubs.Players.Present.PAGE_SIGNED_FROM,
)
page_players_joined_on = self.page.xpath(
Clubs.Players.Past.PAGE_SIGNED_FROM if self.past else Clubs.Players.Present.PAGE_SIGNED_FROM,
)
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)
Expand All @@ -71,9 +75,7 @@ def __parse_club_players(self) -> list[dict]:
Clubs.Players.Past.FOOTS if self.past else Clubs.Players.Present.FOOTS,
remove_empty=False,
)
players_joined_on = self.get_list_by_xpath(
Clubs.Players.Past.JOINED_ON if self.past else Clubs.Players.Present.JOINED_ON,
)
players_joined_on = ["; ".join(e.xpath(Clubs.Players.JOINED_ON)) for e in page_players_joined_on]
players_joined = ["; ".join(e.xpath(Clubs.Players.JOINED)) for e in page_players_infos]
players_signed_from = ["; ".join(e.xpath(Clubs.Players.SIGNED_FROM)) for e in page_players_signed_from]
players_contracts = (
Expand Down
5 changes: 3 additions & 2 deletions app/utils/xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,21 @@ class Players:
SIGNED_FROM = ".//a//img//@title"
MARKET_VALUES = "//td[@class='rechts hauptlink']//text()"
STATUSES = ".//td[@class='hauptlink']//span//@title"
JOINED_ON = ".//text()"

class Present:
PAGE_SIGNED_FROM = "//div[@id='yw1']//td[8]"
PAGE_JOINED_ON = "//div[@id='yw1']//td[7]"
HEIGHTS = "//div[@id='yw1']//td[5]//text()"
FOOTS = "//div[@id='yw1']//td[6]//text()"
JOINED_ON = "//div[@id='yw1']//td[7]//text()"
CONTRACTS = "//div[@id='yw1']//td[9]//text()"

class Past:
PAGE_SIGNED_FROM = "//div[@id='yw1']//td[9]"
PAGE_JOINED_ON = "//div[@id='yw1']//td[8]"
CURRENT_CLUB = "//div[@id='yw1']//td[5]//img//@title"
HEIGHTS = "//div[@id='yw1']//td[6]/text()"
FOOTS = "//div[@id='yw1']//td[7]//text()"
JOINED_ON = "//div[@id='yw1']//td[8]//text()"
CONTRACTS = "//div[@id='yw1']//td[10]//text()"


Expand Down

0 comments on commit 64079fe

Please sign in to comment.