def parse(device, text): multiplier = 1 text = text.replace(",", "") is_dot_in_text = False if '.' in text: text = text.replace(".", "") is_dot_in_text = True if "K" in text: text = text.replace("K", "") multiplier = 1000 if is_dot_in_text: multiplier = 100 if "M" in text: text = text.replace("M", "") multiplier = 1000000 if is_dot_in_text: multiplier = 100000 try: count = int(float(text) * multiplier) except ValueError: print_timeless(COLOR_FAIL + "Cannot parse \"" + text + "\". Probably wrong language, will set English now." + COLOR_ENDC) save_crash(device) switch_to_english(device) raise LanguageChangedException() return count
def do_unfollow(device, username, my_username, check_if_is_follower, on_action): """ :return: whether unfollow was successful """ username_view = device.find( resourceId=f'{device.app_id}:id/follow_list_username', className='android.widget.TextView', text=username) if not username_view.exists(): print(COLOR_FAIL + "Cannot find @" + username + ", skip." + COLOR_ENDC) return False username_view.click() on_action(GetProfileAction(user=username)) sleeper.random_sleep() if_profile_empty = softban_indicator.detect_empty_profile(device) if if_profile_empty: print("Back to the followings list.") device.back() return False if check_if_is_follower and _check_is_follower(device, username, my_username): print("Skip @" + username + ". This user is following you.") print("Back to the followings list.") device.back() return False unfollow_button = device.find(classNameMatches=TEXTVIEW_OR_BUTTON_REGEX, clickable=True, text='Following') if not unfollow_button.exists(): print( COLOR_FAIL + "Cannot find Following button. Maybe not English language is set?" + COLOR_ENDC) save_crash(device) switch_to_english(device) raise LanguageChangedException() unfollow_button.click() confirm_unfollow_button = device.find( resourceId=f'{device.app_id}:id/follow_sheet_unfollow_row', className='android.widget.TextView') if not confirm_unfollow_button.exists(): print(COLOR_FAIL + "Cannot confirm unfollow." + COLOR_ENDC) save_crash(device) device.back() return False confirm_unfollow_button.click() sleeper.random_sleep() _close_confirm_dialog_if_shown(device) softban_indicator.detect_action_blocked_dialog(device) print("Back to the followings list.") device.back() return True
def _follow(device, username, follow_percentage): follow_chance = randint(1, 100) if follow_chance > follow_percentage: return False print("Following...") coordinator_layout = device.find( resourceId='com.instagram.android:id/coordinator_root_layout') if coordinator_layout.exists(): coordinator_layout.scroll(DeviceFacade.Direction.TOP) random_sleep() profile_header_actions_layout = device.find( resourceId='com.instagram.android:id/profile_header_actions_top_row', className='android.widget.LinearLayout') if not profile_header_actions_layout.exists(): print(COLOR_FAIL + "Cannot find profile actions." + COLOR_ENDC) return False follow_button = profile_header_actions_layout.child( classNameMatches=TEXTVIEW_OR_BUTTON_REGEX, clickable=True, textMatches=FOLLOW_REGEX) if not follow_button.exists(): unfollow_button = profile_header_actions_layout.child( classNameMatches=TEXTVIEW_OR_BUTTON_REGEX, clickable=True, textMatches=UNFOLLOW_REGEX) if unfollow_button.exists(): print(COLOR_OKGREEN + "You already follow @" + username + "." + COLOR_ENDC) return False else: print( COLOR_FAIL + "Cannot find neither Follow button, nor Unfollow button. Maybe not " "English language is set?" + COLOR_ENDC) save_crash(device) switch_to_english(device) raise LanguageChangedException() follow_button.click() detect_block(device) print(COLOR_OKGREEN + "Followed @" + username + COLOR_ENDC) random_sleep() return True
def do_unfollow(device, my_username, username, storage, check_if_is_follower, username_view, follow_status_button_view, on_action): """ :return: whether unfollow was successful """ need_to_go_back_to_list = True unfollow_from_list_chance = randint(1, 100) if follow_status_button_view is not None and not check_if_is_follower and unfollow_from_list_chance > 50: # We can unfollow directly here instead of getting inside to profile need_to_go_back_to_list = False print("Unfollowing a profile directly from the following list.") follow_status_button_view.click() else: print("Unfollowing a profile from his profile page.") username_view.click() on_action(GetProfileAction(user=username)) sleeper.random_sleep() if_profile_empty = softban_indicator.detect_empty_profile(device) if if_profile_empty: print("Back to the followings list.") device.back() return False if check_if_is_follower and _check_is_follower(device, username, my_username): print("Skip @" + username + ". This user is following you.") storage.update_follow_status(username, True, True) print("Back to the followings list.") device.back() return False unfollow_button = device.find( classNameMatches=TEXTVIEW_OR_BUTTON_REGEX, clickable=True, text='Following') if not unfollow_button.exists(): print( COLOR_FAIL + "Cannot find Following button. Maybe not English language is set?" + COLOR_ENDC) save_crash(device) switch_to_english(device) raise LanguageChangedException() print(f"Unfollowing @{username}...") unfollow_button.click() sleeper.random_sleep() confirm_unfollow_button = device.find( resourceId=f'{device.app_id}:id/follow_sheet_unfollow_row', className='android.widget.TextView') if not confirm_unfollow_button.exists(): print(COLOR_FAIL + "Cannot confirm unfollow." + COLOR_ENDC) save_crash(device) device.back() return False confirm_unfollow_button.click() sleeper.random_sleep() _close_confirm_dialog_if_shown(device) softban_indicator.detect_action_blocked_dialog(device) if need_to_go_back_to_list: print("Back to the followings list.") device.back() return True
def do_unfollow(device, my_username, username, storage, check_if_is_follower, username_view, follow_status_button_view, on_action): """ :return: whether unfollow was successful """ need_to_go_back_to_list = True unfollow_from_list_chance = randint(1, 100) if follow_status_button_view is not None and not check_if_is_follower and unfollow_from_list_chance > 50: # We can unfollow directly here instead of getting inside to profile need_to_go_back_to_list = False print("Unfollowing a profile directly from the following list.") follow_status_button_view.click() else: print("Unfollowing a profile from their profile page.") username_view.click() on_action(GetProfileAction(user=username)) sleeper.random_sleep() if_profile_empty = softban_indicator.detect_empty_profile(device) if if_profile_empty: print("Back to the followings list.") device.back() return False if check_if_is_follower: if _check_is_follower(device, username, my_username): print("Skip @" + username + ". This user is following you.") storage.update_follow_status(username, is_follow_me=True, do_i_follow_him=True) print("Back to the followings list.") device.back() return False storage.update_follow_status(username, is_follow_me=False, do_i_follow_him=True) unfollow_button = device.find(classNameMatches=TEXTVIEW_OR_BUTTON_REGEX, clickable=True, text='Following') if not unfollow_button.exists(): print(COLOR_FAIL + "Cannot find Following button. Maybe not English language is set?" + COLOR_ENDC) save_crash(device) switch_to_english(device) raise LanguageChangedException() print(f"Unfollowing @{username}...") unfollow_button.click() sleeper.random_sleep() unfollow_confirmed = False dialog_view = DialogView(device) if dialog_view.is_visible(): print("Confirming unfollow...") unfollow_confirmed = dialog_view.click_unfollow() if unfollow_confirmed: try: # If the account is private, another popup is shown confirm_button = device.find(classNameMatches=TEXTVIEW_OR_BUTTON_REGEX, clickable=True, text='Unfollow') # If it exists, click unfollow if confirm_button.exists(): print("Private account, confirming unfollow...") confirm_button.click() # Either way, sleep except: pass finally: sleeper.random_sleep() else: softban_indicator.detect_action_blocked_dialog(device) if need_to_go_back_to_list: print("Back to the followings list.") device.back() return True