示例#1
0
def _job_handle_bloggers(device, bloggers, likes_count, follow_percentage,
                         storage, profile_filter, on_interaction):
    class State:
        def __init__(self):
            pass

        is_job_completed = False

    state = State()
    session_state = sessions[-1]

    def on_likes_limit_reached():
        state.is_job_completed = True

    on_interaction = partial(on_interaction,
                             on_likes_limit_reached=on_likes_limit_reached)

    for blogger in bloggers:
        is_myself = blogger == session_state.my_username
        print_timeless("")
        print(COLOR_BOLD + "Handle @" + blogger +
              (is_myself and " (it\'s you)" or "") + COLOR_ENDC)
        completed = False
        on_interaction = partial(on_interaction, blogger=blogger)
        while not completed and not state.is_job_completed:
            try:
                username = None
                if not is_myself:
                    username = blogger
                handle_blogger(device, username, likes_count,
                               follow_percentage, storage, profile_filter,
                               _on_like, on_interaction)
                completed = True
            except KeyboardInterrupt:
                close_instagram(device_id)
                print_copyright(session_state.my_username)
                print_timeless(COLOR_WARNING + "-------- FINISH: " +
                               str(datetime.now().time()) + " --------" +
                               COLOR_ENDC)
                _print_report()
                sys.exit(0)
            except (uiautomator.JsonRPCError, IndexError, HTTPException,
                    timeout):
                print(COLOR_FAIL + traceback.format_exc() + COLOR_ENDC)
                take_screenshot(device)
                print("Try again for @" + blogger + " from the beginning")
                # Hack for the case when IGTV was accidentally opened
                close_instagram(device_id)
                random_sleep()
                open_instagram(device_id)
                get_my_username(device)
            except Exception as e:
                take_screenshot(device)
                close_instagram(device_id)
                _print_report()
                raise e
示例#2
0
 def job():
     handle_blogger(device,
                    blogger,
                    session_state,
                    likes_count,
                    follow_percentage,
                    follow_limit,
                    storage,
                    profile_filter,
                    _on_like,
                    on_interaction)
     state.is_job_completed = True