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: parsing logic for GuestUser to correctly handle Gravatar URLs #25

Merged
merged 1 commit into from
Oct 8, 2024
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
6 changes: 3 additions & 3 deletions src/wikidot/module/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ class GuestUser(AbstractUser):
ユーザー名
unix_name: None
ユーザーのUNIX名(ゲストユーザーのためNone)
avatar_url: None
ユーザーアバターのURL(ゲストユーザーのためNone)
avatar_url: str | None
ユーザーアバターのURL (Gravatar URL)
ip: None
ユーザーのIPアドレス(取得できないためNone)
"""
Expand All @@ -249,7 +249,7 @@ class GuestUser(AbstractUser):
id: None = None
# name: str | None
unix_name: None = None
avatar_url: None = None
avatar_url: str | None = None
ip: None = None


Expand Down
10 changes: 10 additions & 0 deletions src/wikidot/util/parser/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ def user_parse(client: "Client", elem: bs4.Tag) -> user.AbstractUser:
# name=elem.get_text().strip()
# )

# Gravatar URLを持つ場合はGuestUserとする
elif elem.find("img") and "gravatar.com" in elem.find("img")["src"]:
avatar_url = elem.find("img")["src"]
guest_name = elem.get_text().strip().split(" ")[0]
return user.GuestUser(
client=client,
name=guest_name,
avatar_url=avatar_url
)

elif elem.get_text() == "Wikidot":
return user.WikidotUser(client=client)

Expand Down