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

Fix DoB and Age @ Player Profile #48

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 12 additions & 6 deletions app/services/players/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
from datetime import datetime

from app.services.base import TransfermarktBase
from app.utils.utils import (
clean_response,
extract_from_url,
)
from app.utils.regex import REGEX_DOB_AGE
from app.utils.utils import clean_response, extract_from_url, safe_regex
from app.utils.xpath import Players


Expand Down Expand Up @@ -46,12 +44,20 @@ def get_player_profile(self) -> dict:
self.response["fullName"] = self.get_text_by_xpath(Players.Profile.FULL_NAME)
self.response["nameInHomeCountry"] = self.get_text_by_xpath(Players.Profile.NAME_IN_HOME_COUNTRY)
self.response["imageURL"] = self.get_text_by_xpath(Players.Profile.IMAGE_URL)
self.response["dateOfBirth"] = self.get_text_by_xpath(Players.Profile.DATE_OF_BIRTH)
self.response["dateOfBirth"] = safe_regex(
self.get_text_by_xpath(Players.Profile.DATE_OF_BIRTH_AGE),
REGEX_DOB_AGE,
"dob",
)
self.response["placeOfBirth"] = {
"city": self.get_text_by_xpath(Players.Profile.PLACE_OF_BIRTH_CITY),
"country": self.get_text_by_xpath(Players.Profile.PLACE_OF_BIRTH_COUNTRY),
}
self.response["age"] = self.get_text_by_xpath(Players.Profile.AGE)
self.response["age"] = safe_regex(
self.get_text_by_xpath(Players.Profile.DATE_OF_BIRTH_AGE),
REGEX_DOB_AGE,
"age",
)
self.response["height"] = self.get_text_by_xpath(Players.Profile.HEIGHT)
self.response["citizenship"] = self.get_list_by_xpath(Players.Profile.CITIZENSHIP)
self.response["isRetired"] = self.get_text_by_xpath(Players.Profile.RETIRED_SINCE_DATE) is not None
Expand Down
1 change: 1 addition & 0 deletions app/utils/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
REGEX_BG_COLOR: str = r"background-color:(?P<color>.+);"
REGEX_CHART_CLUB_ID: str = r"(?P<club_id>\d+)"
REGEX_COUNTRY_ID: str = r"(?P<id>\d)"
REGEX_DOB_AGE: str = r"^(?P<dob>\w{3} \d{1,2}, \d{4}) \((?P<age>\d{2})\)"
3 changes: 1 addition & 2 deletions app/utils/xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ class Profile:
CURRENT_CLUB_CONTRACT_OPTION = "//span[contains(text(),'Contract option:')]//following::span[1]//text()"
NAME_IN_HOME_COUNTRY = "//span[text()='Name in home country:']//following::span[1]//text()"
FULL_NAME = "//span[text()='Full name:']//following::span[1]//text()"
DATE_OF_BIRTH = "//span[text()='Date of birth:']//following::span[1]//a//text()"
DATE_OF_BIRTH_AGE = "//span[@itemprop='birthDate']//text()"
PLACE_OF_BIRTH_CITY = "//span[text()='Place of birth:']//following::span[1]//span//text()"
PLACE_OF_BIRTH_COUNTRY = "//span[text()='Place of birth:']//following::span[1]//span//img//@title"
AGE = "//span[text()='Age:']//following::span[1]//text()"
HEIGHT = "//span[text()='Height:']//following::span[1]//text()"
CITIZENSHIP = "//span[text()='Citizenship:']//following::span[1]//text()"
POSITION = "//span[text()='Position:']//following::span[1]//text()"
Expand Down
Loading