def get_my_profile_info(device): navigate(device, Tabs.PROFILE) username = None title_view = device(resourceId='com.instagram.android:id/title_view', className='android.widget.TextView') if title_view.exists: username = title_view.text else: print(COLOR_FAIL + "Failed to get username" + COLOR_ENDC) try: followers = _get_followers_count(device) except LanguageChangedException: # Try again on the correct language navigate(device, Tabs.PROFILE) followers = _get_followers_count(device) report_string = "" if username: report_string += "Hello, @" + username + "!" if followers: report_string += " You have " + str(followers) + " followers so far." if not report_string == "": print(report_string) return username, followers
def _open_user_followers(device, username): if username is None: print("Open your followers") followers_button = device(resourceId='com.instagram.android:id/row_profile_header_followers_container', className='android.widget.LinearLayout') followers_button.click.wait() else: navigate(device, Tabs.SEARCH) print("Open user @" + username) search_edit_text = device(resourceId='com.instagram.android:id/action_bar_search_edit_text', className='android.widget.EditText') search_edit_text.set_text(username) device.wait.idle() username_view = device(resourceId='com.instagram.android:id/row_search_user_username', className='android.widget.TextView', text=username) if not username_view.exists: print_timeless(COLOR_FAIL + "Cannot find user @" + username + ", abort." + COLOR_ENDC) return False username_view.click.wait() print("Open @" + username + " followers") followers_button = device(resourceId='com.instagram.android:id/row_profile_header_followers_container', className='android.widget.LinearLayout') followers_button.click.wait() return True
def _open_user_followers(device, username): if username is None: print("Open your followers") followers_button = device.find( resourceIdMatches=FOLLOWERS_BUTTON_ID_REGEX) followers_button.click() else: navigate(device, Tabs.SEARCH) print("Open user @" + username) search_edit_text = device.find( resourceId='com.instagram.android:id/action_bar_search_edit_text', className='android.widget.EditText') search_edit_text.set_text(username) username_view = device.find( resourceId='com.instagram.android:id/row_search_user_username', className='android.widget.TextView', text=username) random_sleep() if not username_view.exists(): print_timeless(COLOR_FAIL + "Cannot find user @" + username + ", abort." + COLOR_ENDC) return False username_view.click() print("Open @" + username + " followers") followers_button = device.find( resourceIdMatches=FOLLOWERS_BUTTON_ID_REGEX) followers_button.click() return True
def wrapper(*args, **kwargs): session_state = sessions[-1] try: func(*args, **kwargs) except KeyboardInterrupt: close_instagram(device_id) print_copyright(session_state.my_username) print_timeless(COLOR_WARNING + "-------- FINISH: " + str(datetime.now().time()) + " --------" + COLOR_ENDC) print_full_report(sessions) sessions.persist(directory=session_state.my_username) sys.exit(0) except (DeviceFacade.JsonRpcError, IndexError, HTTPException, timeout): print(COLOR_FAIL + traceback.format_exc() + COLOR_ENDC) save_crash(device) print("No idea what it was. Let's try again.") # Hack for the case when IGTV was accidentally opened close_instagram(device_id) random_sleep() open_instagram(device_id) navigate(device, Tabs.PROFILE) except LanguageChangedException: print_timeless("") print( "Language was changed. We'll have to start from the beginning." ) navigate(device, Tabs.PROFILE) except Exception as e: save_crash(device) close_instagram(device_id) print_full_report(sessions) sessions.persist(directory=session_state.my_username) raise e
def _switch_to_english(device): print(COLOR_OKGREEN + "Switching to English locale" + COLOR_ENDC) navigate(device, Tabs.PROFILE) print("Changing language in settings") action_bar = device(resourceId='com.instagram.android:id/action_bar', className='android.widget.LinearLayout') options_view = action_bar.child(index=1) options_view.click.wait() settings_button = device( resourceId='com.instagram.android:id/menu_settings_row', className='android.widget.TextView') settings_button.click.wait() list_view = device(resourceId='android:id/list', className='android.widget.ListView') account_item = list_view.child(index=6) account_item.click.wait() list_view = device(resourceId='android:id/list', className='android.widget.ListView') language_item = list_view.child(index=3) language_item.click.wait() search_edit_text = device(resourceId='com.instagram.android:id/search', className='android.widget.EditText') search_edit_text.set_text("english") device.wait.idle() list_view = device( resourceId='com.instagram.android:id/language_locale_list', className='android.widget.ListView') english_item = list_view.child(index=0) english_item.click.wait()
def get_my_username(device): navigate(device, Tabs.PROFILE) title_view = device(resourceId='com.instagram.android:id/title_view', className='android.widget.TextView') if title_view.exists: username = title_view.text print("Hello, @" + username) return username else: print(COLOR_FAIL + "Failed to get username" + COLOR_ENDC) return ""
def get_my_followers(device, storage_followers): navigate(device, Tabs.PROFILE) username = None follower_info = device.find( resourceId= "com.instagram.android:id/row_profile_header_followers_container") follower_info.click() _iterate_over_followers(device, storage_followers) return True
def _open_hashtags(device, hashtag): if hashtag is not None: navigate(device, Tabs.SEARCH) print("Search for #" + hashtag) random_sleep() search_edit_text = device.find( resourceId='com.instagram.android:id/action_bar_search_edit_text', className='android.widget.EditText') search_edit_text.set_text(hashtag) search_hashtag_section = device.find( className='android.widget.FrameLayout', index='2') search_hashtag_section.click() random_sleep() failed = False while True: if failed == True: hashtag_result_view = device.find( resourceId='com.instagram.android:id/recycler_view', className='androidx.recyclerview.widget.RecyclerView') hashtag_result_view.scroll(DeviceFacade.Direction.BOTTOM) nr_post = str(random.randint(2, 8)) search_random_post = device.find( className='android.widget.ImageView', index=nr_post) search_random_post.click() list_view = device.find( resourceId='android:id/list', className='androidx.recyclerview.widget.RecyclerView') random_sleep() list_view.scroll(DeviceFacade.Direction.BOTTOM) random_sleep() search_likes_container = device.find( resourceId='com.instagram.android:id/like_row', className='android.widget.RelativeLayout') search_likes_container.click() wrong_page = device.find( resourceId= 'com.instagram.android:id/row_profile_header_post_count_container', className='android.widget.Button') if not wrong_page.exists(): break device.back() random_sleep() device.back() failed = True else: print("test") return True
def _switch_to_english(device): print(COLOR_OKGREEN + "Switching to English locale" + COLOR_ENDC) navigate(device, Tabs.PROFILE) print("Changing language in settings") action_bar = device(resourceId='com.instagram.android:id/action_bar', className='android.widget.LinearLayout') options_view = action_bar.child(index=1) options_view.click.wait() settings_button = device( resourceId='com.instagram.android:id/menu_settings_row', className='android.widget.TextView') settings_button.click.wait() for account_item_index in range(6, 9): list_view = device(resourceId='android:id/list', className='android.widget.ListView') account_item = list_view.child(index=account_item_index) account_item.click.wait() list_view = device(resourceId='android:id/list', className='android.widget.ListView') language_item = list_view.child(index=3) if not language_item.exists: print(COLOR_FAIL + "Oops, went the wrong way" + COLOR_ENDC) device.press.back() continue language_item.click.wait() search_edit_text = device(resourceId='com.instagram.android:id/search', className='android.widget.EditText') if not search_edit_text.exists: print(COLOR_FAIL + "Oops, went the wrong way" + COLOR_ENDC) device.press.back() device.press.back() continue search_edit_text.set_text("english") device.wait.idle() list_view = device( resourceId='com.instagram.android:id/language_locale_list', className='android.widget.ListView') english_item = list_view.child(index=0) english_item.click.wait() break
def get_my_profile_info(device): navigate(device, Tabs.PROFILE) random_sleep() update_interaction_rect(device) username = None title_view = device.find(resourceId='com.instagram.android:id/title_view', className='android.widget.TextView') if title_view.exists(): username = title_view.get_text() else: print(COLOR_FAIL + "Failed to get username" + COLOR_ENDC) try: followers = _get_followers_count(device) except LanguageChangedException: # Try again on the correct language navigate(device, Tabs.PROFILE) followers = _get_followers_count(device) try: following = get_following_count(device) except LanguageChangedException: # Try again on the correct language navigate(device, Tabs.PROFILE) following = get_following_count(device) report_string = "" if username: report_string += "Hello, @" + username + "! " if followers is not None: report_string += "You have " + str(followers) + " followers" if following is not None: report_string += " and " + str(following) + " followings" report_string += " so far." if not report_string == "": print(report_string) return username, followers, following