Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
• Fix clicking wrong button in a "shop" account #104
Browse files Browse the repository at this point in the history
• Fix bug when switching to English locale
  • Loading branch information
Alexander Mishchenko committed Sep 19, 2020
1 parent 7f20e77 commit 0833684
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 70 deletions.
40 changes: 22 additions & 18 deletions src/action_handle_blogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from src.device_facade import DeviceFacade
from src.interaction_rect_checker import is_in_interaction_rect
from src.language_switcher import switch_to_english, LanguageChangedException
from src.navigation import navigate, Tabs
from src.storage import FollowingStatus
from src.utils import *
Expand Down Expand Up @@ -296,25 +297,28 @@ def _follow(device, username, follow_percentage):

random_sleep()

profile_actions = device.find(resourceId='com.instagram.android:id/profile_header_actions_top_row',
className='android.widget.LinearLayout')
follow_button = profile_actions.child(index=0)

if follow_button.exists():
follow_button.click()
detect_block(device)
bottom_sheet = device.find(resourceId='com.instagram.android:id/layout_container_bottom_sheet',
className='android.widget.FrameLayout')
if bottom_sheet.exists():
print(COLOR_OKGREEN + "Already followed" + COLOR_ENDC)
device.back()
follow_button = device.find(className='android.widget.TextView',
text='Follow')
if not follow_button.exists():
follow_button = device.find(className='android.widget.TextView',
text='Follow Back')
if not follow_button.exists():
unfollow_button = device.find(className='android.widget.TextView',
text='Following')
if unfollow_button.exists():
print(COLOR_OKGREEN + "You already follow @" + username + "." + COLOR_ENDC)
return False
print(COLOR_OKGREEN + "Followed @" + username + COLOR_ENDC)
random_sleep()
return True
else:
print_timeless(COLOR_FAIL + "Failed @" + username + " following." + COLOR_ENDC)
return False
else:
print(COLOR_FAIL + "Cannot find neither Follow button, nor Following button. Maybe not "
"English language is set?" + COLOR_ENDC)
switch_to_english(device)
raise LanguageChangedException()

follow_button.click()
detect_block(device)
print(COLOR_OKGREEN + "Followed @" + username + COLOR_ENDC)
random_sleep()
return True


def _is_follow_limit_reached(session_state, follow_limit, blogger):
Expand Down
54 changes: 2 additions & 52 deletions src/counters_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src.navigation import Tabs, navigate
from src.language_switcher import switch_to_english, LanguageChangedException
from src.utils import *


Expand All @@ -18,56 +18,6 @@ def parse(device, text):
print_timeless(COLOR_FAIL + "Cannot parse \"" + text + "\". Probably wrong language, will set English now." +
COLOR_ENDC)
save_crash(device)
_switch_to_english(device)
switch_to_english(device)
raise LanguageChangedException()
return count


def _switch_to_english(device):
print(COLOR_OKGREEN + "Switching to English locale" + COLOR_ENDC)
navigate(device, Tabs.PROFILE)
print("Changing language in settings")

action_bar = device.find(resourceId='com.instagram.android:id/action_bar',
className='android.widget.LinearLayout')
options_view = action_bar.child(index=2)
options_view.click()

settings_button = device.find(resourceId='com.instagram.android:id/menu_settings_row',
className='android.widget.TextView')
settings_button.click()

for account_item_index in range(6, 9):
list_view = device.find(resourceId='android:id/list',
className='android.widget.ListView')
account_item = list_view.child(index=account_item_index)
account_item.click()

list_view = device.find(resourceId='android:id/list',
className='android.widget.ListView')
language_item = list_view.child(index=3)
if not language_item.exists():
print(COLOR_FAIL + "Oops, went the wrong way" + COLOR_ENDC)
device.back()
continue
language_item.click()

search_edit_text = device.find(resourceId='com.instagram.android:id/search',
className='android.widget.EditText')
if not search_edit_text.exists():
print(COLOR_FAIL + "Oops, went the wrong way" + COLOR_ENDC)
device.back()
device.back()
continue
search_edit_text.set_text("english")

list_view = device.find(resourceId='com.instagram.android:id/language_locale_list',
className='android.widget.ListView')
english_item = list_view.child(index=0)
english_item.click()

break


class LanguageChangedException(Exception):
pass
57 changes: 57 additions & 0 deletions src/language_switcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from src.navigation import navigate, Tabs
from src.utils import *


def switch_to_english(device):
print(COLOR_OKGREEN + "Switching to English locale" + COLOR_ENDC)
navigate(device, Tabs.PROFILE)
print("Changing language in settings")

action_bar = device.find(resourceId='com.instagram.android:id/action_bar',
className='android.widget.LinearLayout')
options_view = action_bar.child(index=2, className='android.widget.ImageView')
if not options_view.exists():
options_view = action_bar.child(index=3, className='android.widget.ImageView')
if not options_view.exists():
print(COLOR_FAIL + "No idea how to open menu..." + COLOR_ENDC)
return
options_view.click()

settings_button = device.find(resourceId='com.instagram.android:id/menu_settings_row',
className='android.widget.TextView')
settings_button.click()

for account_item_index in range(6, 9):
list_view = device.find(resourceId='android:id/list',
className='android.widget.ListView')
account_item = list_view.child(index=account_item_index)
account_item.click()

list_view = device.find(resourceId='android:id/list',
className='android.widget.ListView')
language_item = list_view.child(index=3)
if not language_item.exists():
print(COLOR_FAIL + "Oops, went the wrong way" + COLOR_ENDC)
device.back()
continue
language_item.click()

search_edit_text = device.find(resourceId='com.instagram.android:id/search',
className='android.widget.EditText')
if not search_edit_text.exists():
print(COLOR_FAIL + "Oops, went the wrong way" + COLOR_ENDC)
device.back()
device.back()
continue
search_edit_text.set_text("english")

list_view = device.find(resourceId='com.instagram.android:id/language_locale_list',
className='android.widget.ListView')
english_item = list_view.child(index=0)
english_item.click()

break


class LanguageChangedException(Exception):
pass

0 comments on commit 0833684

Please sign in to comment.