Skip to content

Commit

Permalink
Fix for unhandled exception on userId fetch failure
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanC committed May 19, 2024
1 parent 16bbc6c commit 6bb3cb4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions services/x.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class X:
"""Interact and engage with the X API."""

def GetUserID(username: str) -> int:
def GetUserID(username: str) -> int | None:
"""Fetch an X user by their username and return their unique identifier."""

userId: int | None = None
Expand Down Expand Up @@ -43,13 +43,13 @@ def GetUserPosts(
) -> list[dict[str, int | str]]:
"""Fetch an array of the latest posts from the specified X username."""

userId: int = X.GetUserID(username)

if not userId:
return
posts: list[dict[str, int | str]] = []

userId: int | None = X.GetUserID(username)
entries: list[dict] = []
posts: list[dict[str, int]] = []

if not userId:
return posts

endpoint: str = "https://twitter.com/i/api/graphql/-gxtzCQbBPmOwxnY-SbiHQ/UserTweetsAndReplies"
variables: dict[str, str | int | bool | None] = {
Expand Down

0 comments on commit 6bb3cb4

Please sign in to comment.