Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfwithSword committed Aug 23, 2024
1 parent 1743959 commit dce9bb0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions helpers/twitch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand All @@ -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...")
Expand Down

0 comments on commit dce9bb0

Please sign in to comment.