From a9f1c35911599d1dd93ebaef532da572d981b72d Mon Sep 17 00:00:00 2001 From: WolfwithSword <12175651+WolfwithSword@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:41:50 -0300 Subject: [PATCH] Fix invalid username lookup --- main.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 657aabc..d3fabb9 100644 --- a/main.py +++ b/main.py @@ -192,7 +192,7 @@ async def find_connections_from_videos(twitch: Twitch, videos: list[Video], user if names := re.findall('(@\w+)', v.title): for name in names: n = name.replace("@", "").lower() - if n in BLACKLISTED: + if n in BLACKLISTED or len(n) < 4: continue if n not in users: u = await get_user_by_name(twitch=twitch, username=n) @@ -216,7 +216,11 @@ async def find_connections_from_videos(twitch: Twitch, videos: list[Video], user async def get_user_by_name(twitch: Twitch, username: str): # TODO: possibly optimize to fetch multiple per depth level at once - user = await first(twitch.get_users(logins=[username])) + try: + user = await first(twitch.get_users(logins=[username])) + except Exception as e: + print(f"Exception with username {username}, {e}") + user = None if user and user.display_name.lower() == username.lower(): return user return None @@ -226,7 +230,7 @@ async def get_videos(twitch: Twitch, user: TwitchUser): videos = [] async for v in twitch.get_videos(user_id=user.id, first=MAX_VOD_DEPTH, sort=SortMethod.TIME, video_type=VideoType.ARCHIVE): - if "@" in v.title: + if v and v.title and "@" in v.title: videos.append(v) return videos