Skip to content

Commit

Permalink
fix: issue with player profiles without title ingame (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
TeKrop authored Nov 1, 2023
1 parent 6a2f92d commit 6ea8315
Show file tree
Hide file tree
Showing 6 changed files with 13,462 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"Player-137712", # Private profile
"TeKrop-2217", # Classic profile
"Unknown-1234", # No player
"JohnV1-1190", # Player without any title ingame
]

# httpx client settings
Expand Down
15 changes: 10 additions & 5 deletions app/parsers/player_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __get_summary(self) -> dict:
class_="Profile-player--info",
recursive=False,
)

return {
"username": (
summary_div.find("h1", class_="Profile-player--name").get_text()
Expand All @@ -141,14 +142,18 @@ def __get_summary(self) -> dict:

@staticmethod
def __get_title(profile_div: Tag) -> str | None:
title = (
profile_div.find(
# We return None is there isn't any player title div
if not (
title_tag := profile_div.find(
"h2",
class_="Profile-player--title",
recursive=False,
).get_text()
or None
)
)
):
return None

# Retrieve the title text
title = title_tag.get_text() or None

# Special case : the "no title" means there is no title
return None if title and title.lower() == "no title" else title
Expand Down
28 changes: 28 additions & 0 deletions tests/fixtures/html/players/JohnV1-1190.html

Large diffs are not rendered by default.

Loading

0 comments on commit 6ea8315

Please sign in to comment.