def _comment(device, my_username, comments_list, on_comment): comment_button = device.find(resourceId=f'{device.app_id}:id/row_feed_button_comment', className="android.widget.ImageView") if not comment_button.exists(quick=True) or not ActionBarView.is_in_interaction_rect(comment_button): print("Cannot find comment button – will try to swipe down a bit") device.swipe(DeviceFacade.Direction.TOP) if not comment_button.exists(quick=True): print("Still cannot find comment button – won't comment") return comment_box_exists = False comment_box = None for _ in range(2): print("Open comments of post") comment_button.click() sleeper.random_sleep() comment_box = device.find(resourceId=f'{device.app_id}:id/layout_comment_thread_edittext') if comment_box.exists(quick=True): if not comment_box.is_enabled(): print("Comments are restricted – not commenting...") device.back() return comment_box_exists = True break if not comment_box_exists: print("Couldn't open comments properly - not commenting...") return comment = spin(choice(comments_list)) print(f"Commenting: {comment}") comment_box.set_text(comment) sleeper.random_sleep() post_button = device.find(resourceId=f'{device.app_id}:id/layout_comment_thread_post_button_click_area') post_button.click() sleeper.random_sleep() softban_indicator.detect_action_blocked_dialog(device) device.close_keyboard() just_post = device.find( resourceId=f'{device.app_id}:id/row_comment_textview_comment', text=f"{my_username} {comment}", ) if just_post.exists(True): print("Comment succeed.") on_comment(comment) else: print(COLOR_FAIL + "Failed to check if comment succeed." + COLOR_ENDC) sleeper.random_sleep() print("Go back to post view.") device.back()
def open_likers(device): likes_view = device.find(resourceId=f'{device.app_id}:id/row_feed_textview_likes', className='android.widget.TextView') if likes_view.exists(quick=True) and ActionBarView.is_in_interaction_rect(likes_view): print("Opening post likers") sleeper.random_sleep() likes_view.click() return True else: return False
def _open_photo_and_like(device, row, column, like_percentage, on_like): def open_photo(): # recycler_view has a className 'androidx.recyclerview.widget.RecyclerView' on modern Android versions and # 'android.view.View' on Android 5.0.1 and probably earlier versions recycler_view = device.find(resourceId='android:id/list') row_view = recycler_view.child(index=row + 1) if not row_view.exists(): return False item_view = row_view.child(index=column) if not item_view.exists(): return False item_view.click() return True if not open_photo(): return False sleeper.random_sleep() to_like = True like_chance = randint(1, 100) if like_chance > like_percentage: print("Not going to like image due to like-percentage hit") to_like = False if to_like: print("Double click!") photo_view = device.find( resourceId=f'{device.app_id}:id/layout_container_main', className='android.widget.FrameLayout') photo_view.double_click() sleeper.random_sleep() # If double click didn't work, set like by icon click try: # Click only button which is under the action bar and above the tab bar. # It fixes bugs with accidental back / home clicks. for like_button in device.find( resourceId=f'{device.app_id}:id/row_feed_button_like', className='android.widget.ImageView', selected=False): if ActionBarView.is_in_interaction_rect(like_button): print("Double click didn't work, click on icon.") like_button.click() sleeper.random_sleep() break except DeviceFacade.JsonRpcError: print("Double click worked successfully.") softban_indicator.detect_action_blocked_dialog(device) on_like() print("Back to profile") device.back() return True
def _open_photo_and_like_and_comment(device, row, column, do_like, do_comment, like_percentage, on_like, comment_percentage, comments_list, my_username, on_comment): def open_photo(): # recycler_view has a className 'androidx.recyclerview.widget.RecyclerView' on modern Android versions and # 'android.view.View' on Android 5.0.1 and probably earlier versions recycler_view = device.find(resourceId='android:id/list') row_view = recycler_view.child(index=row + 1) if not row_view.exists(): return False item_view = row_view.child(index=column) if not item_view.exists(): return False item_view.click() return True if not open_photo(): return False sleeper.random_sleep() to_like = False to_comment = False if do_like: to_like = True like_chance = randint(1, 100) if like_chance > like_percentage: print("Not going to like image due to like-percentage hit") to_like = False if do_comment: to_comment = True comment_chance = randint(1, 100) if comment_chance > comment_percentage: print("Not going to comment image due to comment-percentage hit") to_comment = False if to_like: print("Double click!") post_view = device.find(resourceIdMatches=POST_VIEW_ID_REGEX.format( device.app_id, device.app_id), className='android.widget.FrameLayout') if post_view.exists: post_view.double_click() sleeper.random_sleep() if not post_view.exists(quick=True): print(COLOR_OKGREEN + "Accidentally went out of the post page, going back..." + COLOR_ENDC) device.back() else: print( COLOR_FAIL + "Cannot find zoomable_view_container, fallback to the old liking algorithm" + COLOR_ENDC) post_view = device.find( resourceId=f'{device.app_id}:id/layout_container_main', className='android.widget.FrameLayout') post_view.double_click() sleeper.random_sleep() # If like button is not visible, scroll down like_button = device.find( resourceId=f'{device.app_id}:id/row_feed_button_like', className='android.widget.ImageView') if not like_button.exists( quick=True) or not ActionBarView.is_in_interaction_rect( like_button): print("Swiping down a bit to see if is liked") device.swipe(DeviceFacade.Direction.TOP) # If double click didn't work, set like by icon click try: # Click only button which is under the action bar and above the tab bar. # It fixes bugs with accidental back / home clicks. for like_button in device.find( resourceId=f'{device.app_id}:id/row_feed_button_like', className='android.widget.ImageView', selected=False): if ActionBarView.is_in_interaction_rect(like_button): print("Double click didn't work, click on icon.") like_button.click() sleeper.random_sleep() break except DeviceFacade.JsonRpcError: print("Double click worked successfully.") softban_indicator.detect_action_blocked_dialog(device) on_like() if to_comment: _comment(device, my_username, comments_list, on_comment) print("Back to profile") device.back() return True