diff --git a/src/action_handle_blogger.py b/src/action_handle_blogger.py index 3fa78a0..567f3a2 100644 --- a/src/action_handle_blogger.py +++ b/src/action_handle_blogger.py @@ -269,6 +269,7 @@ def open_photo(): except uiautomator.JSONRPCError: print("Double click worked successfully.") + detect_block(device) on_like() print("Back to profile") device.press("back") @@ -291,6 +292,7 @@ def _follow(device, username, follow_percentage): if follow_button.exists(timeout=UI_TIMEOUT): follow_button.click(timeout=UI_TIMEOUT) + detect_block(device) bottom_sheet = device(resourceId='com.instagram.android:id/layout_container_bottom_sheet', className='android.widget.FrameLayout') if bottom_sheet.exists(timeout=UI_TIMEOUT): diff --git a/src/action_unfollow.py b/src/action_unfollow.py index bca0383..164d7a5 100644 --- a/src/action_unfollow.py +++ b/src/action_unfollow.py @@ -109,6 +109,7 @@ def _do_unfollow(device, username, my_username, check_if_is_follower): 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.press("back") return False @@ -138,15 +139,11 @@ def _do_unfollow(device, username, my_username, check_if_is_follower): confirm_unfollow_button.click(timeout=UI_TIMEOUT) random_sleep() - - unfollow_succeed = not _check_if_you_follow(device, username, my_username) - if not unfollow_succeed: - print(COLOR_FAIL + "Unfollow didn't work for some reason." + COLOR_ENDC) - raise UnfollowError("Please check why unfollow doesn't work, you may be blocked!") + detect_block(device) print("Back to the followings list.") device.press("back") - return unfollow_succeed + return True def _check_is_follower(device, username, my_username): @@ -166,23 +163,6 @@ def _check_is_follower(device, username, my_username): return result -def _check_if_you_follow(device, username, my_username): - print("Make sure that you don't still follow @" + username) - followers_container = device(resourceId='com.instagram.android:id/row_profile_header_followers_container', - className='android.widget.LinearLayout') - followers_container.click(timeout=UI_TIMEOUT) - - random_sleep() - - my_username_view = device(resourceId='com.instagram.android:id/follow_list_username', - className='android.widget.TextView', - text=my_username) - result = my_username_view.exists(timeout=UI_TIMEOUT) - print("Back to the profile.") - device.press("back") - return result - - @unique class UnfollowRestriction(Enum): ANY = 0 diff --git a/src/utils.py b/src/utils.py index 762a033..1aee54a 100644 --- a/src/utils.py +++ b/src/utils.py @@ -5,6 +5,8 @@ from random import randint from time import sleep +from src.globals import UI_TIMEOUT + COLOR_HEADER = '\033[95m' COLOR_OKBLUE = '\033[94m' COLOR_OKGREEN = '\033[92m' @@ -85,6 +87,16 @@ def take_screenshot(device): print(COLOR_FAIL + "Cannot save screenshot." + COLOR_ENDC) +def detect_block(device): + block_dialog = device(resourceId='com.instagram.android:id/dialog_root_view', + className='android.widget.FrameLayout') + is_blocked = block_dialog.exists(UI_TIMEOUT) + if is_blocked: + print(COLOR_FAIL + "Probably block dialog is shown." + COLOR_ENDC) + raise ActionBlockedError("Seems that action is blocked. Consider reinstalling Instagram app and be more careful" + " with limits!") + + def print_copyright(username): if hashlib.sha1(username.encode('utf-8')).hexdigest() not in COPYRIGHT_BLACKLIST: print_timeless("\nIf you like this script and want it to be improved, " + COLOR_BOLD + "donate please" @@ -114,3 +126,7 @@ def wrapper(*args, **kwargs): print_timeless = _print_with_time_decorator(print, False) print = _print_with_time_decorator(print, True) + + +class ActionBlockedError(Exception): + pass