Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player trainer profile link & relatives #81

Merged
merged 6 commits into from
Dec 8, 2024
Merged
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
Prev Previous commit
Next Next commit
feat: added related players to player profile
McAroon committed Nov 18, 2024
commit bc3fe3b55643ccd58fc1b1694ff29dc06f55bb62
20 changes: 20 additions & 0 deletions app/services/players/profile.py
Original file line number Diff line number Diff line change
@@ -28,6 +28,25 @@ def __post_init__(self) -> None:
self.page = self.request_url_page()
self.raise_exception_if_not_found(xpath=Players.Profile.URL)

def __parse_player_related_players(self) -> list:
"""
Parse the list of related players from the 'Further information' section on the player page
Returns:
list: A list of dictionaries, each containing player ID and player profile URL
"""
player_urls = self.page.xpath(Players.Profile.RELATED_PLAYERS_URLS)

result = []
for player_url in player_urls:
result.append(
{
"id": extract_from_url(player_url),
"url": player_url,
}
)

return result

def get_player_profile(self) -> dict:
"""
Retrieve and parse the player's profile information, including their personal details,
@@ -90,6 +109,7 @@ def get_player_profile(self) -> dict:
"url": self.get_text_by_xpath(Players.Profile.TRAINER_PROFILE_URL),
"position": self.get_text_by_xpath(Players.Profile.TRAINER_PROFILE_POSITION),
}
self.response["relatedPlayers"] = self.__parse_player_related_players()
self.response["updatedAt"] = datetime.now()

return clean_response(self.response)
3 changes: 3 additions & 0 deletions app/utils/xpath.py
Original file line number Diff line number Diff line change
@@ -49,6 +49,9 @@ class Profile:
SOCIAL_MEDIA = "//div[@class='social-media-toolbar__icons']//@href"
TRAINER_PROFILE_URL = "//a[@class='data-header__box--link']//@href"
TRAINER_PROFILE_POSITION = "//div[@class='dataProfileDaten']//span[1]//text()"
RELATED_PLAYERS_URLS = (
"//div[@class='box tm-player-additional-data']//a[contains(@href, 'profil/spieler')]//@href"
)

class Search:
FOUND = "//text()"
2 changes: 2 additions & 0 deletions tests/players/test_players_profile.py
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@ def test_get_player_profile_28003(len_greater_than_0):
},
"outfitter": And(str, len_greater_than_0),
"socialMedia": And(list, len_greater_than_0),
"relatedPlayers": And(list, len_greater_than_0),
"updatedAt": datetime,
},
)
@@ -193,6 +194,7 @@ def test_get_player_profile_3373(len_greater_than_0):
"url": And(str, len_greater_than_0),
"position": And(str, len_greater_than_0),
},
"relatedPlayers": And(list, len_greater_than_0),
"updatedAt": datetime,
},
)