예제 #1
0
def _do_unfollow(device, username, my_username, check_if_is_follower):
    """
    :return: whether unfollow was successful
    """
    username_view = device.find(
        resourceId='com.instagram.android: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()

    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='com.instagram.android: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()

    random_sleep()
    _close_confirm_dialog_if_shown(device)
    detect_block(device)

    print("Back to the followings list.")
    device.back()
    return True
예제 #2
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
예제 #3
0
def parse(device, text):
    multiplier = 1
    text = text.replace(",", "")
    text = text.replace(".", "")
    if "K" in text:
        text = text.replace("K", "")
        multiplier = 1000
    if "M" in text:
        text = text.replace("M", "")
        multiplier = 1000000
    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
예제 #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='com.instagram.android:id/coordinator_root_layout')
    if coordinator_layout.exists():
        coordinator_layout.scroll(DeviceFacade.Direction.TOP)

    random_sleep()

    follow_button = device.find(className='android.widget.TextView',
                                clickable=True,
                                text='Follow')
    if not follow_button.exists():
        follow_button = device.find(className='android.widget.TextView',
                                    clickable=True,
                                    text='Follow Back')
    if not follow_button.exists():
        unfollow_button = device.find(className='android.widget.TextView',
                                      clickable=True,
                                      text='Following')
        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 Following button. Maybe not "
                "English language is set?" + COLOR_ENDC)
            switch_to_english(device)
            raise LanguageChangedException()

    follow_button.click()
    detect_block(device)
    print(COLOR_OKGREEN + "Followed @" + username + COLOR_ENDC)
    random_sleep()
    return True