diff --git a/helpers/twitch_utils.py b/helpers/twitch_utils.py index 0079e70..0e1efac 100644 --- a/helpers/twitch_utils.py +++ b/helpers/twitch_utils.py @@ -19,7 +19,10 @@ def __init__(self, config: TCNConfig, twitch: Twitch): self.blacklisted_channelnames = self.config.blacklisted_channelnames async def init_primary_user(self, username: str, users: dict): - primary_user = await self.get_user_by_name(username) + if username.strip() in self.blacklisted_channelnames: + return + + primary_user = await self.get_user_by_name(username.strip()) if not primary_user: return @@ -60,9 +63,9 @@ async def find_connections_from_videos(self, videos: list[Video], if user.size >= self.config.max_children: user.color = 'red' break - if names := re.findall('(@\w+)', v.title): + if names := re.findall(r'(@\w+)', v.title): for name in names: - n = name.replace("@", "").lower() + n = name.replace("@", "").lower().strip() if not (4 <= len(n) <= 25) or n in self.blacklisted_channelnames: continue if n not in users: @@ -72,7 +75,7 @@ async def find_connections_from_videos(self, videos: list[Video], user.add_child(child) child.add_child(user) # Bidirectional enforcement users[child.name] = child - elif n not in [x.name for x in user.children]: + elif n not in [x.name.strip() for x in user.children]: user.add_child(users[n]) if user not in users[n].children: # Bidirectional enforcement users[n].add_child(user) # Bidirectional enforcement diff --git a/main.py b/main.py index 3105035..415e2a8 100644 --- a/main.py +++ b/main.py @@ -56,7 +56,7 @@ async def twitch_run(): await asyncio.gather(*chunked_users) else: for primary_username in config.primary_channelnames: - await twitch_utils.init_primary_user(primary_username, users) + await twitch_utils.init_primary_user(username=primary_username, users=users) if len(users) == 0: logger.error("No valid primary channels were found. Please reconfigure the primary_channel(s)") @@ -66,17 +66,17 @@ async def twitch_run(): # Loop 'recursively' until we hit a limit while not all_done(users, depth): - non_processed_users = list([_u for _u in list(users) if not users[_u].processed]) + non_processed_users = list([_u.strip() for _u in list(users) if not users[_u.strip()].processed]) if config.concurrency and len(non_processed_users) > 1: chunks = list(chunkify(non_processed_users, config.max_concurrency)) for chunk in chunks: if chunk: - chunked_users = [twitch_utils.scan_user(user=users[_u], users=users) + chunked_users = [twitch_utils.scan_user(user=users[_u.strip()], users=users) for _u in chunk] await asyncio.gather(*chunked_users) else: for user in non_processed_users: - await twitch_utils.scan_user(user=users[user], users=users) + await twitch_utils.scan_user(user=users[user.strip()], users=users) depth += 1 progress_time = "{:.2f}".format(time_since(start_time=start_time)) logger.info(f"At depth level {depth} with {len(users)} users. {progress_time}s...")