From be095aaaa996bf02916176dac9c9848b8172dad5 Mon Sep 17 00:00:00 2001 From: Alexander Mishchenko Date: Sat, 10 Oct 2020 13:24:31 +0300 Subject: [PATCH] =?UTF-8?q?=E2=80=A2=20Fix=20ignoring=20--follow-limit=20w?= =?UTF-8?q?hen=20following=20private/empty=20accounts=20=E2=80=A2=20Fix=20?= =?UTF-8?q?crash=20when=20trying=20to=20follow=20a=20user=20who's=20alread?= =?UTF-8?q?y=20"Requested"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/action_handle_blogger.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/action_handle_blogger.py b/src/action_handle_blogger.py index df4ddba..a3be727 100644 --- a/src/action_handle_blogger.py +++ b/src/action_handle_blogger.py @@ -10,6 +10,8 @@ FOLLOWERS_BUTTON_ID_REGEX = 'com.instagram.android:id/row_profile_header_followers_container' \ '|com.instagram.android:id/row_profile_header_container_followers' TEXTVIEW_OR_BUTTON_REGEX = 'android.widget.TextView|android.widget.Button' +FOLLOW_REGEX = 'Follow|Follow Back' +UNFOLLOW_REGEX = 'Following|Requested' def handle_blogger(device, @@ -224,10 +226,12 @@ def _interact_with_user(device, recycler_view = device.find(resourceId='android:id/list') if not recycler_view.exists(): print(COLOR_OKGREEN + "Private / empty account." + COLOR_ENDC) - followed = _follow(device, - username, - follow_percentage) if profile_filter.can_follow_private_or_empty() else False - if not followed: + if can_follow and profile_filter.can_follow_private_or_empty(): + followed = _follow(device, + username, + follow_percentage) + else: + followed = False print(COLOR_OKGREEN + "Skip user." + COLOR_ENDC) return False, followed @@ -320,22 +324,24 @@ def _follow(device, username, follow_percentage): random_sleep() - follow_button = device.find(classNameMatches=TEXTVIEW_OR_BUTTON_REGEX, - clickable=True, - text='Follow') - if not follow_button.exists(): - follow_button = device.find(classNameMatches=TEXTVIEW_OR_BUTTON_REGEX, - clickable=True, - text='Follow Back') + 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 = device.find(classNameMatches=TEXTVIEW_OR_BUTTON_REGEX, - clickable=True, - text='Following') + 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 Following button. Maybe not " + 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)