From 0ac1a750199e429ff607738ed99675942e529a54 Mon Sep 17 00:00:00 2001 From: r74tech Date: Sun, 6 Oct 2024 05:54:46 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20fix:=20parsing=20logic=20for=20G?= =?UTF-8?q?uestUser=20to=20correctly=20handle=20Gravatar=20URLs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified the user_parse function to identify GuestUser by the presence of Gravatar URLs. The Gravatar image URL is extracted and set as the avatar_url attribute for the GuestUser. --- src/wikidot/module/user.py | 6 +++--- src/wikidot/util/parser/user.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/wikidot/module/user.py b/src/wikidot/module/user.py index 8b661aa..ab19add 100644 --- a/src/wikidot/module/user.py +++ b/src/wikidot/module/user.py @@ -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) """ @@ -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 diff --git a/src/wikidot/util/parser/user.py b/src/wikidot/util/parser/user.py index bdd997a..674ffb9 100644 --- a/src/wikidot/util/parser/user.py +++ b/src/wikidot/util/parser/user.py @@ -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)