Пример #1
0
def main(device):
    random.seed()
    colorama.init()

    # create device from insomniac main()
    global device_id
    device_id = device
    if not check_adb_connection(is_device_id_provided=(device_id is not None)):
        return

    print("Instagram version: " + get_instagram_version())

    device = create_device(False, device_id)
    if device is None:
        return

    session_state = SessionState()

    print_timeless(COLOR_WARNING + "\n-------- START: " +
                   str(session_state.startTime) + " --------" + COLOR_ENDC)
    open_instagram(device_id)
    session_state.my_username, \
    session_state.my_followers_count, \
    session_state.my_following_count = get_my_profile_info(device)
    storage_followers = StorageFollowers(session_state.my_username)

    get_my_followers(device, storage_followers)
Пример #2
0
def main():
    random.seed()
    colorama.init()
    print_timeless(COLOR_HEADER + "Insomniac " + get_version() + "\n" +
                   COLOR_ENDC)

    ok, args = _parse_arguments()
    if not ok:
        return

    global device_id
    device_id = args.device
    if not check_adb_connection(is_device_id_provided=(device_id is not None)):
        return

    device = create_device(args.old, device_id)
    if device is None:
        return

    mode = None
    is_interact_enabled = len(args.interact) > 0
    is_unfollow_enabled = args.unfollow is not None
    is_unfollow_non_followers_enabled = args.unfollow_non_followers is not None
    is_unfollow_any_enabled = args.unfollow_any is not None
    is_remove_mass_followers_enabled = args.remove_mass_followers is not None and int(
        args.remove_mass_followers) > 0
    total_enabled = int(is_interact_enabled) + int(is_unfollow_enabled) + int(is_unfollow_non_followers_enabled) \
        + int(is_unfollow_any_enabled) + int(is_remove_mass_followers_enabled)
    if total_enabled == 0:
        print_timeless(
            COLOR_FAIL +
            "You have to specify one of the actions: --interact, --unfollow, "
            "--unfollow-non-followers, --unfollow-any, --remove-mass-followers"
            + COLOR_ENDC)
        return
    elif total_enabled > 1:
        print_timeless(
            COLOR_FAIL +
            "Running Insomniac with two or more actions is not supported yet."
            + COLOR_ENDC)
        return
    else:
        if is_interact_enabled:
            print("Action: interact with @" +
                  ", @".join(str(blogger) for blogger in args.interact))
            mode = Mode.INTERACT
        elif is_unfollow_enabled:
            print("Action: unfollow " + str(args.unfollow))
            mode = Mode.UNFOLLOW
        elif is_unfollow_non_followers_enabled:
            print("Action: unfollow " + str(args.unfollow_non_followers) +
                  " non followers")
            mode = Mode.UNFOLLOW_NON_FOLLOWERS
        elif is_unfollow_any_enabled:
            print("Action: unfollow any " + str(args.unfollow_any))
            mode = Mode.UNFOLLOW_ANY
        elif is_remove_mass_followers_enabled:
            print("Action: remove " + str(args.remove_mass_followers) +
                  " mass followers")
            mode = Mode.REMOVE_MASS_FOLLOWERS

    profile_filter = Filter()

    while True:
        session_state = SessionState()
        session_state.args = args.__dict__
        sessions.append(session_state)

        print_timeless(COLOR_WARNING + "\n-------- START: " +
                       str(session_state.startTime) + " --------" + COLOR_ENDC)
        open_instagram(device_id)
        session_state.my_username,\
            session_state.my_followers_count,\
            session_state.my_following_count = get_my_profile_info(device)
        storage = Storage(session_state.my_username)

        # IMPORTANT: in each job we assume being on the top of the Profile tab already
        if mode == Mode.INTERACT:
            on_interaction = partial(_on_interaction,
                                     likes_limit=int(args.total_likes_limit))

            _job_handle_bloggers(
                device, args.interact, args.likes_count,
                int(args.follow_percentage),
                int(args.follow_limit) if args.follow_limit else None, storage,
                profile_filter, args.interactions_count, on_interaction)
        elif mode == Mode.UNFOLLOW:
            print_timeless("")
            _job_unfollow(device, get_value(args.unfollow, "Unfollow {}",
                                            100), storage,
                          int(args.min_following),
                          UnfollowRestriction.FOLLOWED_BY_SCRIPT)
        elif mode == Mode.UNFOLLOW_NON_FOLLOWERS:
            print_timeless("")
            _job_unfollow(
                device,
                get_value(args.unfollow_non_followers,
                          "Unfollow {} non followers", 100), storage,
                int(args.min_following),
                UnfollowRestriction.FOLLOWED_BY_SCRIPT_NON_FOLLOWERS)
        elif mode == Mode.UNFOLLOW_ANY:
            print_timeless("")
            _job_unfollow(device,
                          get_value(args.unfollow_any,
                                    "Unfollow {} any", 100), storage,
                          int(args.min_following), UnfollowRestriction.ANY)
        elif mode == Mode.REMOVE_MASS_FOLLOWERS:
            _job_remove_mass_followers(device, int(args.remove_mass_followers),
                                       int(args.max_following), storage)

        close_instagram(device_id)
        print_copyright(session_state.my_username)
        session_state.finishTime = datetime.now()
        print_timeless(COLOR_WARNING + "-------- FINISH: " +
                       str(session_state.finishTime) + " --------" +
                       COLOR_ENDC)

        if args.repeat:
            print_full_report(sessions)
            print_timeless("")
            repeat = get_value(args.repeat, "Sleep for {} minutes", 180)
            try:
                sleep(60 * repeat)
            except KeyboardInterrupt:
                print_full_report(sessions)
                sessions.persist(directory=session_state.my_username)
                sys.exit(0)
        else:
            break

    print_full_report(sessions)
    sessions.persist(directory=session_state.my_username)
Пример #3
0
def main():
    random.seed()
    colorama.init()
    print_timeless(COLOR_HEADER + "Insomniac " + get_version() + "\n" +
                   COLOR_ENDC)

    ok, args = _parse_arguments()
    if not ok:
        return

    global device_id
    device_id = args.device
    if not check_adb_connection(is_device_id_provided=(device_id is not None)):
        return

    print("Instagram version: " + get_instagram_version())

    device = create_device(args.old, device_id)
    if device is None:
        return

    if len(args.interact) > 0 and args.interaction_users_amount:
        args.__setattr__("full_interact", args.interact.copy())

    while True:
        mode = None
        is_interact_enabled = len(args.interact) > 0
        is_unfollow_enabled = args.unfollow is not None
        is_unfollow_non_followers_enabled = args.unfollow_non_followers is not None
        is_unfollow_any_enabled = args.unfollow_any is not None
        is_remove_mass_followers_enabled = args.remove_mass_followers is not None and int(
            args.remove_mass_followers) > 0
        total_enabled = int(is_interact_enabled) + int(is_unfollow_enabled) + int(is_unfollow_non_followers_enabled) \
                        + int(is_unfollow_any_enabled) + int(is_remove_mass_followers_enabled)
        if total_enabled == 0:
            print_timeless(
                COLOR_FAIL +
                "You have to specify one of the actions: --interact, --unfollow, "
                "--unfollow-non-followers, --unfollow-any, --remove-mass-followers"
                + COLOR_ENDC)
            return
        elif total_enabled > 1:
            print_timeless(
                COLOR_FAIL +
                "Running Insomniac with two or more actions is not supported yet."
                + COLOR_ENDC)
            return
        else:
            if is_interact_enabled:
                print("Action: interact with @" +
                      ", @".join(str(blogger) for blogger in args.interact))
                mode = Mode.INTERACT
            elif is_unfollow_enabled:
                print("Action: unfollow " + str(args.unfollow))
                mode = Mode.UNFOLLOW
            elif is_unfollow_non_followers_enabled:
                print("Action: unfollow " + str(args.unfollow_non_followers) +
                      " non followers")
                mode = Mode.UNFOLLOW_NON_FOLLOWERS
            elif is_unfollow_any_enabled:
                print("Action: unfollow any " + str(args.unfollow_any))
                mode = Mode.UNFOLLOW_ANY
            elif is_remove_mass_followers_enabled:
                print("Action: remove " + str(args.remove_mass_followers) +
                      " mass followers")
                mode = Mode.REMOVE_MASS_FOLLOWERS

        profile_filter = Filter(args.filters)

        start_work_hour, stop_work_hour = 1, 24

        if args.working_hours:
            start_work_hour, stop_work_hour = get_left_right_values(
                args.working_hours, "Working hours {}", (9, 21))

            if not (1 <= start_work_hour <= 24):
                print(COLOR_FAIL +
                      "Working-hours left-boundary ({0}) is not valid. "
                      "Using (9) instead".format(start_work_hour) + COLOR_ENDC)
                start_work_hour = 9

            if not (1 <= stop_work_hour <= 24):
                print(COLOR_FAIL +
                      "Working-hours right-boundary ({0}) is not valid. "
                      "Using (21) instead".format(stop_work_hour) + COLOR_ENDC)
                stop_work_hour = 21

        now = datetime.now()

        if not (start_work_hour <= now.hour <= stop_work_hour):
            print(
                "Current Time: {0} which is out of working-time range ({1}-{2})"
                .format(now.strftime("%H:%M:%S"), start_work_hour,
                        stop_work_hour))
            next_execution = '0 {0} * * *'.format(start_work_hour)

            time_to_sleep_seconds = (croniter(
                next_execution, now).get_next(datetime) - now).seconds + 60
            print("Going to sleep until working time ({0} minutes)...".format(
                time_to_sleep_seconds / 60))

            sleep(time_to_sleep_seconds)
            continue

        if len(args.full_interact) > 0 and args.interaction_users_amount:
            args.interact = args.full_interact.copy()
            users_amount = get_value(args.interaction_users_amount,
                                     "Interaction user amount {}", 100)

            if users_amount >= len(args.interact):
                print(
                    "interaction-users-amount parameter is equal or higher then the users-interact list. "
                    "Choosing all list for interaction.")
            else:
                amount_to_remove = len(args.interact) - users_amount
                for i in range(0, amount_to_remove):
                    args.interact.remove(random.choice(args.interact))

        session_state = SessionState()
        session_state.args = args.__dict__
        sessions.append(session_state)

        print_timeless(COLOR_WARNING + "\n-------- START: " +
                       str(session_state.startTime) + " --------" + COLOR_ENDC)
        open_instagram(device_id)
        session_state.my_username,\
            session_state.my_followers_count,\
            session_state.my_following_count = get_my_profile_info(device)
        storage = Storage(session_state.my_username)

        # IMPORTANT: in each job we assume being on the top of the Profile tab already
        if mode == Mode.INTERACT:
            on_interaction = partial(_on_interaction,
                                     likes_limit=int(args.total_likes_limit))

            _job_handle_bloggers(
                device, args.interact, args.likes_count,
                int(args.follow_percentage),
                int(args.follow_limit) if args.follow_limit else None,
                int(args.total_follow_limit)
                if args.total_follow_limit else None, storage, profile_filter,
                args.interactions_count, on_interaction)
        elif mode == Mode.UNFOLLOW:
            print_timeless("")
            _job_unfollow(device, get_value(args.unfollow, "Unfollow {}",
                                            100), storage,
                          int(args.min_following),
                          UnfollowRestriction.FOLLOWED_BY_SCRIPT)
        elif mode == Mode.UNFOLLOW_NON_FOLLOWERS:
            print_timeless("")
            _job_unfollow(
                device,
                get_value(args.unfollow_non_followers,
                          "Unfollow {} non followers", 100), storage,
                int(args.min_following),
                UnfollowRestriction.FOLLOWED_BY_SCRIPT_NON_FOLLOWERS)
        elif mode == Mode.UNFOLLOW_ANY:
            print_timeless("")
            _job_unfollow(device,
                          get_value(args.unfollow_any,
                                    "Unfollow {} any", 100), storage,
                          int(args.min_following), UnfollowRestriction.ANY)
        elif mode == Mode.REMOVE_MASS_FOLLOWERS:
            _job_remove_mass_followers(device, int(args.remove_mass_followers),
                                       int(args.max_following), storage)

        close_instagram(device_id)
        print_copyright(session_state.my_username)
        session_state.finishTime = datetime.now()
        print_timeless(COLOR_WARNING + "-------- FINISH: " +
                       str(session_state.finishTime) + " --------" +
                       COLOR_ENDC)

        if args.repeat:
            print_full_report(sessions)
            print_timeless("")
            repeat = get_value(args.repeat, "Sleep for {} minutes", 180)
            try:
                sleep(60 * repeat)
                _refresh_args_by_conf_file(args)
            except KeyboardInterrupt:
                print_full_report(sessions)
                sessions.persist(directory=session_state.my_username)
                sys.exit(0)
        else:
            break

    print_full_report(sessions)
    sessions.persist(directory=session_state.my_username)