Skip to content

Commit dce9bb0

Browse files
committed
cleanup
1 parent 1743959 commit dce9bb0

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

helpers/twitch_utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ def __init__(self, config: TCNConfig, twitch: Twitch):
1919
self.blacklisted_channelnames = self.config.blacklisted_channelnames
2020

2121
async def init_primary_user(self, username: str, users: dict):
22-
primary_user = await self.get_user_by_name(username)
22+
if username.strip() in self.blacklisted_channelnames:
23+
return
24+
25+
primary_user = await self.get_user_by_name(username.strip())
2326
if not primary_user:
2427
return
2528

@@ -60,9 +63,9 @@ async def find_connections_from_videos(self, videos: list[Video],
6063
if user.size >= self.config.max_children:
6164
user.color = 'red'
6265
break
63-
if names := re.findall('(@\w+)', v.title):
66+
if names := re.findall(r'(@\w+)', v.title):
6467
for name in names:
65-
n = name.replace("@", "").lower()
68+
n = name.replace("@", "").lower().strip()
6669
if not (4 <= len(n) <= 25) or n in self.blacklisted_channelnames:
6770
continue
6871
if n not in users:
@@ -72,7 +75,7 @@ async def find_connections_from_videos(self, videos: list[Video],
7275
user.add_child(child)
7376
child.add_child(user) # Bidirectional enforcement
7477
users[child.name] = child
75-
elif n not in [x.name for x in user.children]:
78+
elif n not in [x.name.strip() for x in user.children]:
7679
user.add_child(users[n])
7780
if user not in users[n].children: # Bidirectional enforcement
7881
users[n].add_child(user) # Bidirectional enforcement

main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async def twitch_run():
5656
await asyncio.gather(*chunked_users)
5757
else:
5858
for primary_username in config.primary_channelnames:
59-
await twitch_utils.init_primary_user(primary_username, users)
59+
await twitch_utils.init_primary_user(username=primary_username, users=users)
6060

6161
if len(users) == 0:
6262
logger.error("No valid primary channels were found. Please reconfigure the primary_channel(s)")
@@ -66,17 +66,17 @@ async def twitch_run():
6666

6767
# Loop 'recursively' until we hit a limit
6868
while not all_done(users, depth):
69-
non_processed_users = list([_u for _u in list(users) if not users[_u].processed])
69+
non_processed_users = list([_u.strip() for _u in list(users) if not users[_u.strip()].processed])
7070
if config.concurrency and len(non_processed_users) > 1:
7171
chunks = list(chunkify(non_processed_users, config.max_concurrency))
7272
for chunk in chunks:
7373
if chunk:
74-
chunked_users = [twitch_utils.scan_user(user=users[_u], users=users)
74+
chunked_users = [twitch_utils.scan_user(user=users[_u.strip()], users=users)
7575
for _u in chunk]
7676
await asyncio.gather(*chunked_users)
7777
else:
7878
for user in non_processed_users:
79-
await twitch_utils.scan_user(user=users[user], users=users)
79+
await twitch_utils.scan_user(user=users[user.strip()], users=users)
8080
depth += 1
8181
progress_time = "{:.2f}".format(time_since(start_time=start_time))
8282
logger.info(f"At depth level {depth} with {len(users)} users. {progress_time}s...")

0 commit comments

Comments
 (0)