Ejemplo n.º 1
0
def get_my_profile_info(device, username):
    try:
        profile_view = TabBarView(device).navigate_to_profile()
        sleeper.random_sleep()

        ActionBarView.create_instance(device)

        if username is not None:
            if not profile_view.change_to_username(username):
                print(COLOR_FAIL +
                      f"Couldn't switch user to {username}, abort!" +
                      COLOR_ENDC)
                device.back()
                raise UserSwitchFailedException()

        print("Refreshing your profile status...")
        profile_view.refresh()
        sleeper.random_sleep()
        username, followers, following = profile_view.get_profile_info(
            swipe_up_if_needed=True)
    except UserSwitchFailedException as e:
        raise e
    except Exception as e:
        print(COLOR_FAIL + describe_exception(e) + COLOR_ENDC)
        save_crash(device, e)
        switch_to_english(device)

        # Try again on the correct language
        profile_view = TabBarView(device).navigate_to_profile()
        sleeper.random_sleep()

        ActionBarView.create_instance(device)

        if username is not None:
            if not profile_view.change_to_username(username):
                print(COLOR_FAIL +
                      f"Couldn't switch user to {username}, abort!" +
                      COLOR_ENDC)
                device.back()
                raise UserSwitchFailedException()

        print("Refreshing your profile status...")
        profile_view.refresh()
        sleeper.random_sleep()
        username, followers, following = profile_view.get_profile_info(
            swipe_up_if_needed=True)

    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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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=f'{device.app_id}:id/coordinator_root_layout')
    if coordinator_layout.exists():
        coordinator_layout.scroll(DeviceFacade.Direction.TOP)

    sleeper.random_sleep()

    profile_header_main_layout = device.find(resourceId=f"{device.app_id}:id/profile_header_fixed_list",
                                             className='android.widget.LinearLayout')

    shop_button = profile_header_main_layout.child(className='android.widget.Button',
                                                   clickable=True,
                                                   textMatches=SHOP_REGEX)

    if shop_button.exists(quick=True):
        follow_button = profile_header_main_layout.child(className='android.widget.Button',
                                                         clickable=True,
                                                         textMatches=FOLLOW_REGEX)
        if not follow_button.exists():
            print(COLOR_FAIL + "Look like a shop profile without an option to follow, continue." + COLOR_ENDC)
            return False
    else:
        profile_header_actions_layout = device.find(resourceId=f'{device.app_id}: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)
                return False

    follow_button.click()
    softban_indicator.detect_action_blocked_dialog(device)
    print(COLOR_OKGREEN + "Followed @" + username + COLOR_ENDC)
    sleeper.random_sleep()
    return True
Ejemplo n.º 5
0
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 get_my_profile_info(device):
    try:
        profile_view = TabBarView(device).navigate_to_profile()
        sleeper.random_sleep()

        print("Refreshing your profile status...")
        profile_view.refresh()
        sleeper.random_sleep()

        ActionBarView.update_interaction_rect(device)

        username, followers, following = profile_view.get_profile_info()
    except Exception as e:
        print(COLOR_FAIL + f"Exception: {e}" + COLOR_ENDC)
        save_crash(device, e)
        switch_to_english(device)

        # Try again on the correct language
        profile_view = TabBarView(device).navigate_to_profile()
        sleeper.random_sleep()

        print("Refreshing your profile status...")
        profile_view.refresh()
        sleeper.random_sleep()

        ActionBarView.update_interaction_rect(device)

        username, followers, following = profile_view.get_profile_info()

    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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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