From 6bb3cb48f2f70151fdd9d7f712c1a424bd15345b Mon Sep 17 00:00:00 2001 From: EthanC <16727756+EthanC@users.noreply.github.com> Date: Sun, 19 May 2024 00:16:04 -0500 Subject: [PATCH] Fix for unhandled exception on userId fetch failure --- services/x.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/services/x.py b/services/x.py index 4b3c821..8b93f05 100644 --- a/services/x.py +++ b/services/x.py @@ -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 @@ -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] = {