Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions GramAddict/plugins/action_unfollow_followers.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ def iterate_over_followings(
total_unfollows_limit_reached = False
posts_end_detector.notify_new_page()
prev_screen_iterated_followings = []
# variables to save appeared usernames
seen_users = set()
seen_user_threshold = 3
while True:
screen_iterated_followings = []
logger.info("Iterate over visible followings.")
Expand All @@ -302,6 +305,8 @@ def iterate_over_followings(
)
row_height, n_users = inspect_current_view(user_list)
for item in user_list:
# inner user_list counter
seen_user_count = 0
cur_row_height = item.get_height()
if cur_row_height < row_height:
continue
Expand All @@ -316,6 +321,10 @@ def iterate_over_followings(

username = user_name_view.get_text()
screen_iterated_followings.append(username)
# check if a username has seen previously
if username in seen_users:
seen_user_count += 1
seen_users.add(username)
if username not in checked:
checked[username] = None

Expand Down Expand Up @@ -409,6 +418,13 @@ def iterate_over_followings(

if screen_iterated_followings != prev_screen_iterated_followings:
prev_screen_iterated_followings = screen_iterated_followings
# exit if reach seen threshold
if seen_user_count > seen_user_threshold:
logger.info(
"Reached the following list end, finish.",
extra={"color": f"{Fore.GREEN}"},
)
return
logger.info("Need to scroll now.", extra={"color": f"{Fore.GREEN}"})
list_view = device.find(
resourceId=self.ResourceID.LIST,
Expand Down