def navigate_to_feed(): # Open post posts_view_list = PostsGridView(device).open_random_post() if posts_view_list is None: return None return posts_view_list
def extract_hashtag_profiles_and_interact(device, hashtag, instructions, iteration_callback, iteration_callback_pre_conditions, on_action): print("Interacting with #{0}-{1}".format(hashtag, instructions.value)) if not search_for(device, hashtag=hashtag, on_action=on_action): return # Switch to Recent tab if instructions == HashtagInteractionType.RECENT_LIKERS: print("Switching to Recent tab") tab_layout = device.find(resourceId=f'{device.app_id}:id/tab_layout', className='android.widget.LinearLayout') if tab_layout.exists(): tab_layout.child(index=1).click() else: print("Can't Find recent tab. Interacting with Popular.") # Sleep longer because posts loading takes time sleeper.random_sleep(multiplier=2.0) # Open post posts_view_list = PostsGridView(device).open_random_post() if posts_view_list is None: return posts_end_detector = ScrollEndDetector(repeats_to_end=2) def pre_conditions(liker_username, liker_username_view): posts_end_detector.notify_username_iterated(liker_username) return iteration_callback_pre_conditions(liker_username, liker_username_view) while True: if not open_likers(device): print(COLOR_OKGREEN + "No likes, let's scroll down." + COLOR_ENDC) posts_view_list.scroll_down() continue print("List of likers is opened.") posts_end_detector.notify_new_page() sleeper.random_sleep() should_continue_using_source = iterate_over_likers(device, iteration_callback, pre_conditions) if not should_continue_using_source: break if posts_end_detector.is_the_end(): break else: posts_view_list.scroll_down()
def navigate_to_feed(): if not search_for(device, hashtag=hashtag, on_action=on_action): return None # Switch to Recent tab if instructions == HashtagInteractionType.RECENT_LIKERS or instructions == HashtagInteractionType.RECENT_POSTS: print("Switching to Recent tab") tab_layout = device.find( resourceId=f'{device.app_id}:id/tab_layout', className='android.widget.LinearLayout') if tab_layout.exists(): tab_layout.child(index=1).click() else: print("Can't Find recent tab. Interacting with Popular.") # Sleep longer because posts loading takes time sleeper.random_sleep(multiplier=2.0) # Open post posts_view_list = PostsGridView(device).open_random_post() if posts_view_list is None: return None return posts_view_list