From 41a0d4b6d4c345f9b252c8702f6c52098802be67 Mon Sep 17 00:00:00 2001 From: Felipe Allegretti Date: Wed, 14 Aug 2024 05:32:12 -0300 Subject: [PATCH] feat: add contracts to clubs players (#72) --- app/services/clubs/players.py | 7 ++++++- app/utils/xpath.py | 1 + tests/clubs/test_clubs_players.py | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/services/clubs/players.py b/app/services/clubs/players.py index b804a31..686ba2d 100644 --- a/app/services/clubs/players.py +++ b/app/services/clubs/players.py @@ -77,6 +77,9 @@ def __parse_club_players(self) -> list[dict]: 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 = ( + [None] * len(players_ids) if self.past else self.get_list_by_xpath(Clubs.Players.Present.CONTRACTS) + ) players_marketvalues = self.get_list_by_xpath(Clubs.Players.MARKET_VALUES) players_statuses = ["; ".join(e.xpath(Clubs.Players.STATUSES)) for e in page_players_infos] @@ -94,10 +97,11 @@ def __parse_club_players(self) -> list[dict]: "joinedOn": joined_on, "joined": joined, "signedFrom": signed_from, + "contract": contract, "marketValue": market_value, "status": status, } - for idx, name, position, dob, age, nationality, current_club, height, foot, joined_on, joined, signed_from, market_value, status, in zip( # noqa: E501 + for idx, name, position, 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, @@ -110,6 +114,7 @@ def __parse_club_players(self) -> list[dict]: players_joined_on, players_joined, players_signed_from, + players_contracts, players_marketvalues, players_statuses, ) diff --git a/app/utils/xpath.py b/app/utils/xpath.py index 41d0dfd..5257b34 100644 --- a/app/utils/xpath.py +++ b/app/utils/xpath.py @@ -156,6 +156,7 @@ class Present: PAGE_JOINED_ON = "//div[@id='yw1']//td[7]" HEIGHTS = "//div[@id='yw1']//td[5]//text()" FOOTS = "//div[@id='yw1']//td[6]//text()" + CONTRACTS = "//div[@id='yw1']//td[9]//text()" class Past: PAGE_SIGNED_FROM = "//div[@id='yw1']//td[9]" diff --git a/tests/clubs/test_clubs_players.py b/tests/clubs/test_clubs_players.py index 7796d01..3bc5668 100644 --- a/tests/clubs/test_clubs_players.py +++ b/tests/clubs/test_clubs_players.py @@ -45,6 +45,7 @@ def test_get_club_players( "joinedOn": Or("", And(str, len_greater_than_0, regex_date_mmm_dd_yyyy)), "joined": Or("", And(str, len_greater_than_0)), "signedFrom": Or("", And(str, len_greater_than_0)), + "contract": Or(None, And(str, regex_date_mmm_dd_yyyy)), "marketValue": And(str, len_greater_than_0, regex_market_value), "status": Or("", And(str, len_greater_than_0)), },