Skip to content

Commit

Permalink
Fix DoB and Age @ Player Profile
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeall committed Dec 8, 2023
1 parent df4f027 commit bc22b28
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 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,14 @@ 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

0 comments on commit bc22b28

Please sign in to comment.