def _job_handle_bloggers(device, bloggers, likes_count, storage, on_interaction): class State: def __init__(self): pass is_job_completed = False state = State() 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: print(COLOR_BOLD + "\nHandle @" + blogger + COLOR_ENDC) is_handled = False while not is_handled and not state.is_job_completed: # noinspection PyBroadException try: handle_blogger(device, blogger, likes_count, storage, _on_like, on_interaction) is_handled = True except KeyboardInterrupt: print(COLOR_OKBLUE + "-------- FINISH: " + str(datetime.now().time()) + " --------" + COLOR_ENDC) _print_report() sys.exit(0) except Exception: is_handled = False print(COLOR_FAIL + traceback.format_exc() + COLOR_ENDC) print "Try again for @" + blogger + " from the beginning"
def _job_handle_bloggers(device, bloggers, likes_count, follow_percentage, storage, 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, _on_like, on_interaction) completed = True except KeyboardInterrupt: 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() random_sleep() open_instagram(device_id) get_my_username(device) except Exception as e: take_screenshot(device) _print_report() raise e
def _job_handle_bloggers(device, bloggers, likes_count, storage, on_interaction): class State: def __init__(self): pass is_job_completed = False state = State() 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: print(COLOR_BOLD + "\nHandle @" + blogger + COLOR_ENDC) is_handled = False on_interaction = partial(on_interaction, blogger=blogger) while not is_handled and not state.is_job_completed: try: handle_blogger(device, blogger, likes_count, storage, _on_like, on_interaction) is_handled = True except KeyboardInterrupt: print(COLOR_OKBLUE + "-------- FINISH: " + str(datetime.now().time()) + " --------" + COLOR_ENDC) _print_report() sys.exit(0) except (uiautomator.JsonRPCError, IndexError, HTTPException, timeout): is_handled = False print(COLOR_FAIL + traceback.format_exc() + COLOR_ENDC) print("Try again for @" + blogger + " from the beginning") # Hack for the case when IGTV was accidentally opened close_instagram() random_sleep() open_instagram() except Exception as e: _print_report() raise e