From 9ddbd1ee60fe67265f0d395e9d84fbcbfb165882 Mon Sep 17 00:00:00 2001 From: Yuval Moravchick Date: Sun, 11 Feb 2024 12:10:24 +0200 Subject: [PATCH 01/11] # workaround test for bug #285/#301 --- GramAddict/core/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/GramAddict/core/views.py b/GramAddict/core/views.py index e91f77a3..d6fe2e5d 100644 --- a/GramAddict/core/views.py +++ b/GramAddict/core/views.py @@ -919,6 +919,10 @@ def detect_media_type(content_desc) -> Tuple[Optional[MediaType], Optional[int]] ) obj_count = n_photos + n_videos media_type = MediaType.CAROUSEL + # workaround test for bug #285/#301 + if obj_count == 0: + media_type = MediaType.REEL # it might be better to set it to UNKNOWN + # end of workaround test return media_type, obj_count def _like_in_post_view( From 50b41813faec06763eaab7c24661df8eb59fdf0c Mon Sep 17 00:00:00 2001 From: Yuval Moravchick Date: Sun, 11 Feb 2024 12:43:18 +0200 Subject: [PATCH 02/11] # workaround test for bug #285/#301 --- GramAddict/core/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/GramAddict/core/views.py b/GramAddict/core/views.py index d6fe2e5d..ec763a30 100644 --- a/GramAddict/core/views.py +++ b/GramAddict/core/views.py @@ -922,6 +922,7 @@ def detect_media_type(content_desc) -> Tuple[Optional[MediaType], Optional[int]] # workaround test for bug #285/#301 if obj_count == 0: media_type = MediaType.REEL # it might be better to set it to UNKNOWN + logger.info("Activating workaround test for Bug #285 - switching to REEL media type") # end of workaround test return media_type, obj_count From b47f40d62f1dbb4122e7ea7e7dc68c780df806b4 Mon Sep 17 00:00:00 2001 From: Yuval Moravchick Date: Mon, 12 Feb 2024 09:59:00 +0200 Subject: [PATCH 03/11] attempt to fix bug #367 - not enough waiting time for the followers list to load --- GramAddict/core/device_facade.py | 17 ++++++++++++++++- GramAddict/core/utils.py | 9 +++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/GramAddict/core/device_facade.py b/GramAddict/core/device_facade.py index 60185b8a..31db23a6 100644 --- a/GramAddict/core/device_facade.py +++ b/GramAddict/core/device_facade.py @@ -1,5 +1,6 @@ import logging import string +import time from datetime import datetime from enum import Enum, auto from inspect import stack @@ -12,7 +13,7 @@ import uiautomator2 -from GramAddict.core.utils import random_sleep +from GramAddict.core.utils import random_sleep, wait_for_element logger = logging.getLogger(__name__) @@ -130,8 +131,22 @@ def find( def back(self, modulable: bool = True): logger.debug("Press back button.") self.deviceV2.press("back") + # attempt to fix bug #367 - not enough waiting time for the followers list to load? random_sleep(modulable=modulable) + selectors = [ + {'resourceId': 'com.instagram.android:id/follow_list_container'}, + {'resourceId': 'com.instagram.android:id/row_user_container_base'}, + {'resourceId': 'com.instagram.android:id/recommended_user_row_content_identifier'} + ] + + # Wait for each element + for selector in selectors: + if not wait_for_element(self.deviceV2, selector): + logger.debug(f"Element with selector {selector} not found within 15 seconds.") + # Handle the case where the element is not found + # You can either break, continue, or take some other action + def start_screenrecord(self, output="debug_0000.mp4", fps=20): import imageio diff --git a/GramAddict/core/utils.py b/GramAddict/core/utils.py index 5f8be6ad..da8ad735 100644 --- a/GramAddict/core/utils.py +++ b/GramAddict/core/utils.py @@ -731,6 +731,15 @@ def inspect_current_view(user_list) -> Tuple[int, int]: logger.debug(f"There are {n_users} users fully visible in that view.") return row_height, n_users +# used by back function device_facade.py - attempt to fix bug #367 +def wait_for_element(device, selector, timeout=15): + end_time = time.time() + timeout + while time.time() < end_time: + if device(**selector).exists: + return True + time.sleep(1) + return False + class ActionBlockedError(Exception): pass From c82629418e61b2a9751ee18cc771ba5f98d2741e Mon Sep 17 00:00:00 2001 From: Yuval Moravchick Date: Mon, 12 Feb 2024 10:00:13 +0200 Subject: [PATCH 04/11] attempt to fix bug #367 - not enough waiting time for the followers list to load --- GramAddict/core/device_facade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GramAddict/core/device_facade.py b/GramAddict/core/device_facade.py index 31db23a6..63471044 100644 --- a/GramAddict/core/device_facade.py +++ b/GramAddict/core/device_facade.py @@ -143,7 +143,7 @@ def back(self, modulable: bool = True): # Wait for each element for selector in selectors: if not wait_for_element(self.deviceV2, selector): - logger.debug(f"Element with selector {selector} not found within 15 seconds.") + logger.debug(f"[Trying to avoid bug #367] Element with selector {selector} not found within 15 seconds.") # Handle the case where the element is not found # You can either break, continue, or take some other action From 7e06ddb5c8342351b215875e532012b85c840d95 Mon Sep 17 00:00:00 2001 From: Yuval Moravchick Date: Mon, 12 Feb 2024 12:01:54 +0200 Subject: [PATCH 05/11] attempt to fix bug #367 - not enough waiting time for the followers list to load --- GramAddict/core/device_facade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GramAddict/core/device_facade.py b/GramAddict/core/device_facade.py index 63471044..7fbd0d74 100644 --- a/GramAddict/core/device_facade.py +++ b/GramAddict/core/device_facade.py @@ -143,7 +143,7 @@ def back(self, modulable: bool = True): # Wait for each element for selector in selectors: if not wait_for_element(self.deviceV2, selector): - logger.debug(f"[Trying to avoid bug #367] Element with selector {selector} not found within 15 seconds.") + logger.info(f"[Trying to avoid bug #367] Element with selector {selector} not found within 15 seconds.") # Handle the case where the element is not found # You can either break, continue, or take some other action From 2bcd7a34f1afe625d00eec5944761ae78eb6d7c7 Mon Sep 17 00:00:00 2001 From: Yuval Moravchick Date: Mon, 12 Feb 2024 23:34:01 +0200 Subject: [PATCH 06/11] attempt to fix bug #367 - not enough waiting time for the followers list to load --- GramAddict/core/device_facade.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/GramAddict/core/device_facade.py b/GramAddict/core/device_facade.py index 7fbd0d74..2dfab7d1 100644 --- a/GramAddict/core/device_facade.py +++ b/GramAddict/core/device_facade.py @@ -135,15 +135,16 @@ def back(self, modulable: bool = True): random_sleep(modulable=modulable) selectors = [ - {'resourceId': 'com.instagram.android:id/follow_list_container'}, + #{'resourceId': 'com.instagram.android:id/follow_list_container'}, {'resourceId': 'com.instagram.android:id/row_user_container_base'}, - {'resourceId': 'com.instagram.android:id/recommended_user_row_content_identifier'} + #{'resourceId': 'com.instagram.android:id/recommended_user_row_content_identifier'} ] # Wait for each element for selector in selectors: - if not wait_for_element(self.deviceV2, selector): - logger.info(f"[Trying to avoid bug #367] Element with selector {selector} not found within 15 seconds.") + logger.info(f"[Trying to avoid bug #367] Waiting for element with selector {selector} to appear.") + if not wait_for_element(self.deviceV2, selector, timeout=5): + logger.info(f"Element with selector {selector} was not found within 5 seconds.") # Handle the case where the element is not found # You can either break, continue, or take some other action From 38b3a32480287b01a1e2b2e87c728434d142a11a Mon Sep 17 00:00:00 2001 From: Yuval Moravchick Date: Tue, 13 Feb 2024 18:55:30 +0200 Subject: [PATCH 07/11] attempt to fix bug #367 - not enough waiting time for the followers list to load --- GramAddict/core/device_facade.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GramAddict/core/device_facade.py b/GramAddict/core/device_facade.py index 2dfab7d1..02730559 100644 --- a/GramAddict/core/device_facade.py +++ b/GramAddict/core/device_facade.py @@ -135,9 +135,9 @@ def back(self, modulable: bool = True): random_sleep(modulable=modulable) selectors = [ - #{'resourceId': 'com.instagram.android:id/follow_list_container'}, + {'resourceId': 'com.instagram.android:id/follow_list_container'}, {'resourceId': 'com.instagram.android:id/row_user_container_base'}, - #{'resourceId': 'com.instagram.android:id/recommended_user_row_content_identifier'} + {'resourceId': 'com.instagram.android:id/recommended_user_row_content_identifier'} ] # Wait for each element From 899050a03ec74f0ae8d2b741e3c703787a13cdd5 Mon Sep 17 00:00:00 2001 From: Yuval Moravchick Date: Wed, 14 Feb 2024 13:13:04 +0200 Subject: [PATCH 08/11] attempt to fix bug #367 - not enough waiting time for the followers list to load --- GramAddict/core/device_facade.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GramAddict/core/device_facade.py b/GramAddict/core/device_facade.py index 02730559..575bcd1e 100644 --- a/GramAddict/core/device_facade.py +++ b/GramAddict/core/device_facade.py @@ -143,8 +143,8 @@ def back(self, modulable: bool = True): # Wait for each element for selector in selectors: logger.info(f"[Trying to avoid bug #367] Waiting for element with selector {selector} to appear.") - if not wait_for_element(self.deviceV2, selector, timeout=5): - logger.info(f"Element with selector {selector} was not found within 5 seconds.") + if not wait_for_element(self.deviceV2, selector, timeout=3): + logger.info(f"Element with selector {selector} was not found within 3 seconds.") # Handle the case where the element is not found # You can either break, continue, or take some other action From e8d2a5c248d3ec324ca34bba5e85739d5c3e829c Mon Sep 17 00:00:00 2001 From: Yuval Moravchick Date: Wed, 14 Feb 2024 13:24:13 +0200 Subject: [PATCH 09/11] attempt to fix bug #367 - not enough waiting time for the followers list to load --- GramAddict/core/device_facade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GramAddict/core/device_facade.py b/GramAddict/core/device_facade.py index 575bcd1e..f5644f43 100644 --- a/GramAddict/core/device_facade.py +++ b/GramAddict/core/device_facade.py @@ -144,7 +144,7 @@ def back(self, modulable: bool = True): for selector in selectors: logger.info(f"[Trying to avoid bug #367] Waiting for element with selector {selector} to appear.") if not wait_for_element(self.deviceV2, selector, timeout=3): - logger.info(f"Element with selector {selector} was not found within 3 seconds.") + logger.debug(f"Element with selector {selector} was not found within 3 seconds.") # Handle the case where the element is not found # You can either break, continue, or take some other action From 19df9fe751b0d1da2fd5a4d1e0902bd7e63342ab Mon Sep 17 00:00:00 2001 From: Yuval Moravchick Date: Fri, 16 Feb 2024 19:07:01 +0200 Subject: [PATCH 10/11] attempt to fix bug #367 - not enough waiting time for the followers list to load --- GramAddict/core/device_facade.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/GramAddict/core/device_facade.py b/GramAddict/core/device_facade.py index f5644f43..e1db25bb 100644 --- a/GramAddict/core/device_facade.py +++ b/GramAddict/core/device_facade.py @@ -131,22 +131,8 @@ def find( def back(self, modulable: bool = True): logger.debug("Press back button.") self.deviceV2.press("back") - # attempt to fix bug #367 - not enough waiting time for the followers list to load? - random_sleep(modulable=modulable) - selectors = [ - {'resourceId': 'com.instagram.android:id/follow_list_container'}, - {'resourceId': 'com.instagram.android:id/row_user_container_base'}, - {'resourceId': 'com.instagram.android:id/recommended_user_row_content_identifier'} - ] - - # Wait for each element - for selector in selectors: - logger.info(f"[Trying to avoid bug #367] Waiting for element with selector {selector} to appear.") - if not wait_for_element(self.deviceV2, selector, timeout=3): - logger.debug(f"Element with selector {selector} was not found within 3 seconds.") - # Handle the case where the element is not found - # You can either break, continue, or take some other action + random_sleep(modulable=modulable) def start_screenrecord(self, output="debug_0000.mp4", fps=20): import imageio From 6ef920abe19438eaf90702144f9e0e685bd38d51 Mon Sep 17 00:00:00 2001 From: Yuval Moravchick Date: Mon, 26 Feb 2024 09:14:17 +0200 Subject: [PATCH 11/11] - --- GramAddict/core/device_facade.py | 1 - GramAddict/core/handle_sources.py | 27 +++++++++++++++++++-------- GramAddict/core/navigation.py | 26 ++++++++++++++------------ 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/GramAddict/core/device_facade.py b/GramAddict/core/device_facade.py index e1db25bb..5c06a687 100644 --- a/GramAddict/core/device_facade.py +++ b/GramAddict/core/device_facade.py @@ -131,7 +131,6 @@ def find( def back(self, modulable: bool = True): logger.debug("Press back button.") self.deviceV2.press("back") - random_sleep(modulable=modulable) def start_screenrecord(self, output="debug_0000.mp4", fps=20): diff --git a/GramAddict/core/handle_sources.py b/GramAddict/core/handle_sources.py index 3b65de9a..38e8fd85 100644 --- a/GramAddict/core/handle_sources.py +++ b/GramAddict/core/handle_sources.py @@ -33,6 +33,7 @@ UniversalActions, case_insensitive_re, ) +from uiautomator2.exceptions import UiObjectNotFoundError logger = logging.getLogger(__name__) @@ -715,14 +716,23 @@ def scrolled_to_top(): return row_search.exists() while True: - logger.info("Iterate over visible followers.") - screen_iterated_followers = [] - screen_skipped_followers_count = 0 - scroll_end_detector.notify_new_page() - user_list = device.find( - resourceIdMatches=self.ResourceID.USER_LIST_CONTAINER, - ) - row_height, n_users = inspect_current_view(user_list) + try: + logger.info("Iterate over visible followers.") + screen_iterated_followers = [] + screen_skipped_followers_count = 0 + scroll_end_detector.notify_new_page() + user_list = device.find( + resourceIdMatches=self.ResourceID.USER_LIST_CONTAINER, + ) + row_height, n_users = inspect_current_view(user_list) + except UiObjectNotFoundError: + logger.info( + "Unable to find USER_LIST_CONTAINER elements, clicking on the back button again", + extra={"color": f"{Fore.RED}"}, + ) + device.back() + continue + try: for item in user_list: cur_row_height = item.get_height() @@ -792,6 +802,7 @@ def scrolled_to_top(): extra={"color": f"{Fore.GREEN}"}, ) + if is_myself and scrolled_to_top(): logger.info("Scrolled to top, finish.", extra={"color": f"{Fore.GREEN}"}) return diff --git a/GramAddict/core/navigation.py b/GramAddict/core/navigation.py index 49fa76e5..5bf796cc 100644 --- a/GramAddict/core/navigation.py +++ b/GramAddict/core/navigation.py @@ -68,18 +68,20 @@ def nav_to_hashtag_or_place(device, target, current_job): TargetView = HashTagView if current_job.startswith("hashtag") else PlacesView - if current_job.endswith("recent"): - logger.info("Switching to Recent tab.") - recent_tab = TargetView(device)._getRecentTab() - if recent_tab.exists(Timeout.MEDIUM): - recent_tab.click() - else: - return False - - if UniversalActions(device)._check_if_no_posts(): - UniversalActions(device)._reload_page() - if UniversalActions(device)._check_if_no_posts(): - return False + # when searching for a hashtag, the recent tab is not available anymore in version 263.2.0.19.104 + + # if current_job.endswith("recent"): + # logger.info("Switching to Recent tab.") + # recent_tab = TargetView(device)._getRecentTab() + # if recent_tab.exists(Timeout.MEDIUM): + # recent_tab.click() + # else: + # return False + # + # if UniversalActions(device)._check_if_no_posts(): + # UniversalActions(device)._reload_page() + # if UniversalActions(device)._check_if_no_posts(): + # return False result_view = TargetView(device)._getRecyclerView() FistImageInView = TargetView(device)._getFistImageView(result_view)