From 9d334f3a9533bd3e7e9ae9d7ffda0208f2fcda67 Mon Sep 17 00:00:00 2001 From: Ken Date: Sat, 22 Jun 2024 19:16:09 -0700 Subject: [PATCH 1/3] fix: fix unfollow job run into unlimited loop due to Instagrame loop back to the first following username after the end of list #379 - add username duplicated check in the loop and exit out when seeing more than 3 usernames that appear previously. --- .../plugins/action_unfollow_followers.py | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/GramAddict/plugins/action_unfollow_followers.py b/GramAddict/plugins/action_unfollow_followers.py index d30a6a97..9af91c32 100644 --- a/GramAddict/plugins/action_unfollow_followers.py +++ b/GramAddict/plugins/action_unfollow_followers.py @@ -237,15 +237,15 @@ def sort_followings_by_date(self, device, newest_to_oldest=False) -> bool: return True def iterate_over_followings( - self, - device, - count, - on_unfollow, - storage, - unfollow_restriction, - my_username, - posts_end_detector, - job_name, + self, + device, + count, + on_unfollow, + storage, + unfollow_restriction, + my_username, + posts_end_detector, + job_name, ): # Wait until list is rendered sorted = False @@ -294,6 +294,8 @@ def iterate_over_followings( total_unfollows_limit_reached = False posts_end_detector.notify_new_page() prev_screen_iterated_followings = [] + seen_users = set() + seen_user_threshold = 3 while True: screen_iterated_followings = [] logger.info("Iterate over visible followings.") @@ -302,6 +304,7 @@ def iterate_over_followings( ) row_height, n_users = inspect_current_view(user_list) for item in user_list: + seen_user_count = 0 cur_row_height = item.get_height() if cur_row_height < row_height: continue @@ -316,6 +319,9 @@ def iterate_over_followings( username = user_name_view.get_text() screen_iterated_followings.append(username) + if username in seen_users: + seen_user_count += 1 + seen_users.add(username) if username not in checked: checked[username] = None @@ -409,6 +415,12 @@ def iterate_over_followings( if screen_iterated_followings != prev_screen_iterated_followings: prev_screen_iterated_followings = screen_iterated_followings + 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, From 2b5ec0a2c875efe35188f84d27bb3f84681345c1 Mon Sep 17 00:00:00 2001 From: Ken Date: Sat, 22 Jun 2024 19:22:29 -0700 Subject: [PATCH 2/3] Revert "fix: fix unfollow job run into unlimited loop due to Instagrame loop back to the first following username after the end of list #379" This reverts commit 9d334f3a9533bd3e7e9ae9d7ffda0208f2fcda67. --- .../plugins/action_unfollow_followers.py | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/GramAddict/plugins/action_unfollow_followers.py b/GramAddict/plugins/action_unfollow_followers.py index 9af91c32..d30a6a97 100644 --- a/GramAddict/plugins/action_unfollow_followers.py +++ b/GramAddict/plugins/action_unfollow_followers.py @@ -237,15 +237,15 @@ def sort_followings_by_date(self, device, newest_to_oldest=False) -> bool: return True def iterate_over_followings( - self, - device, - count, - on_unfollow, - storage, - unfollow_restriction, - my_username, - posts_end_detector, - job_name, + self, + device, + count, + on_unfollow, + storage, + unfollow_restriction, + my_username, + posts_end_detector, + job_name, ): # Wait until list is rendered sorted = False @@ -294,8 +294,6 @@ def iterate_over_followings( total_unfollows_limit_reached = False posts_end_detector.notify_new_page() prev_screen_iterated_followings = [] - seen_users = set() - seen_user_threshold = 3 while True: screen_iterated_followings = [] logger.info("Iterate over visible followings.") @@ -304,7 +302,6 @@ def iterate_over_followings( ) row_height, n_users = inspect_current_view(user_list) for item in user_list: - seen_user_count = 0 cur_row_height = item.get_height() if cur_row_height < row_height: continue @@ -319,9 +316,6 @@ def iterate_over_followings( username = user_name_view.get_text() screen_iterated_followings.append(username) - if username in seen_users: - seen_user_count += 1 - seen_users.add(username) if username not in checked: checked[username] = None @@ -415,12 +409,6 @@ def iterate_over_followings( if screen_iterated_followings != prev_screen_iterated_followings: prev_screen_iterated_followings = screen_iterated_followings - 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, From 90bea6582103a7c0a7b25f92c1737b4be198f265 Mon Sep 17 00:00:00 2001 From: Ken Date: Sat, 22 Jun 2024 19:25:01 -0700 Subject: [PATCH 3/3] fix: fix unfollow job run into unlimited loop due to Instagrame loop back to the first following username after the end of list #379 - add username duplicated check in the loop and exit out when seeing more than 3 usernames that appear previously. --- GramAddict/plugins/action_unfollow_followers.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/GramAddict/plugins/action_unfollow_followers.py b/GramAddict/plugins/action_unfollow_followers.py index d30a6a97..6ca1fffb 100644 --- a/GramAddict/plugins/action_unfollow_followers.py +++ b/GramAddict/plugins/action_unfollow_followers.py @@ -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.") @@ -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 @@ -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 @@ -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,