fix #379
Description
Unfollow job runs into unlimited loop due to Instagrame loop back to the first following username after the end of list #379
Fixes # (issue)
Type of change
Please delete options that are not relevant.
- [ X] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
- [ X] Test A
- [ ] Test B
Test Configuration:
- Device Model or Emulator: TCL 30Z
- Android Verison: Android 14
- Instagram Version: 299.0.0.34.111
Checklist:
- [ X] My code follows the style guidelines of this project
- [X ] I have performed a self-review of my own code
- [ X] I have commented my code, particularly in hard-to-understand areas
- [ X] I have made corresponding changes to the documentation
- [ X] My changes generate no new warnings
- [ X] I have tested my code in every way I can think of to prove my fix is effective or that my feature works
- [ X] Any dependent changes have been merged and published in downstream modules
Specifically, the seen_user_count is reset to 0 for each item in user_list inside the loop, which means it will always be either 0 or 1 and never accumulate across iterations. This effectively makes the threshold check with seen_user_threshold meaningless. @kenpyfin
Problematic snippet
while True:
screen_iterated_followings = []
logger.info("Iterate over visible followings.")
user_list = device.find(
resourceIdMatches=self.ResourceID.USER_LIST_CONTAINER,
)
row_height, n_users = inspect_current_view(user_list)
for item in user_list:
# inner user_list counter
seen_user_count = 0 ##it resets the **_seen_user_** count so it can only by **0** or **1**. This renders **_seen_user_threshold_** useless.
cur_row_height = item.get_height()
if cur_row_height < row_height:
continue
user_info_view = item.child(index=1)
user_name_view = user_info_view.child(index=0).child()
if not user_name_view.exists():
logger.info(
"Next item not found: probably reached end of the screen.",
extra={"color": f"{Fore.GREEN}"},
)
break
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)
Corected
you should put seen_user_count = 0 before the while True: loop
I have uploaded the corrected code :)
https://pastebin.com/5nKD0LaA
Problematic snippet
while True: screen_iterated_followings = [] logger.info("Iterate over visible followings.") user_list = device.find( resourceIdMatches=self.ResourceID.USER_LIST_CONTAINER, ) row_height, n_users = inspect_current_view(user_list) for item in user_list: # inner user_list counter seen_user_count = 0 ##it resets the **_seen_user_** count so it can only by **0** or **1**. This renders **_seen_user_threshold_** useless. cur_row_height = item.get_height() if cur_row_height < row_height: continue user_info_view = item.child(index=1) user_name_view = user_info_view.child(index=0).child() if not user_name_view.exists(): logger.info( "Next item not found: probably reached end of the screen.", extra={"color": f"{Fore.GREEN}"}, ) break 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)Corected
you should put seen_user_count = 0 before the while True: loop
I have uploaded the corrected code :)
https://pastebin.com/5nKD0LaA
When scrolling down the following list, if you reach the end and continue to scroll, it shows the following users from the beginning but only one or two at the bottom of the page. The user_list variable gives you all usernames in the visible screen. So seen_user_count will have value more than 1. The reason I put the seen_user_countinside theuser_list ` loop is to prevent occasional "half way" scroll that leaves 1 or 2 previous shown username in the viewable screen and cause early exit of the action.
That's my understanding of the code.
@drago1520