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

Find unique user based on lowercase email compare #12

Merged
merged 2 commits into from
Jan 15, 2025
Merged
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
7 changes: 4 additions & 3 deletions src/wordpress_markdown_blog_loader/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,12 @@ def get_unique_user_by_name(self, name: str, email: Optional[str]) -> "User":
if len(users) == 0:
raise ValueError(f"author '{name}' not found on {self.endpoint.host}")
elif len(users) > 1:
user = next(filter(lambda u: email and u.email == email, users), None)
user = next(filter(lambda u: email and u.email.lower() == email.lower(), users), None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if u.email is none, this will throw an error.

if not user:
raise ValueError(
f"Multiple authors named '{name}' found, none with email {email}"
f"Multiple authors named '{name}' found, none with email {email} (possible: { {u.email for u in users} })."
)
return user
return users[0]

def posts(self, query: dict = None) -> Iterator["Post"]:
Expand Down Expand Up @@ -546,4 +547,4 @@ def get_tag_id_by_name(self, tag: str) -> str:
"invalid tag '{}' try one of\n {}".format(
tag, ",\n ".join(self.tags.keys())
)
)
)