Skip to content

Commit

Permalink
Update to v3.7.17
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Mishchenko committed Jul 5, 2021
1 parent 6cf9d48 commit 9848fe1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
2 changes: 1 addition & 1 deletion insomniac/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__title__ = 'insomniac'
__description__ = 'Simple Instagram bot for automated Instagram interaction using Android.'
__url__ = 'https://github.com/alexal1/Insomniac/'
__version__ = '3.7.15'
__version__ = '3.7.17'
__debug_mode__ = False
__author__ = 'Insomniac Team'
__author_email__ = '[email protected]'
Expand Down
4 changes: 2 additions & 2 deletions insomniac/device_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def is_screen_locked(self):

def is_alive(self):
if self.deviceV1 is not None:
return self.deviceV1.alive()
return self.deviceV1.server.alive
else:
return self.deviceV2._is_alive()

Expand Down Expand Up @@ -557,7 +557,7 @@ def wait(self):
if self.viewV1 is not None:
import uiautomator
try:
self.deviceV1.wait.idle()
self.device.deviceV1.wait.idle()
except uiautomator.JsonRPCError as e:
raise DeviceFacade.JsonRpcError(e)
return True
Expand Down
2 changes: 1 addition & 1 deletion insomniac/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, my_username, args):
self._reset_state()

if my_username is None:
print(COLOR_FAIL + "No username, so the script won't read/write from the database" + COLOR_ENDC)
print(COLOR_OKGREEN + "No username, so the script won't read/write from the database" + COLOR_ENDC)
return

global IS_USING_DATABASE
Expand Down
58 changes: 47 additions & 11 deletions insomniac/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from insomniac.sleeper import sleeper
from insomniac.utils import *


TEXTVIEW_OR_BUTTON_REGEX = 'android.widget.TextView|android.widget.Button'


Expand Down Expand Up @@ -182,7 +181,11 @@ def navigate_to(self, tab: TabBarTabs):
# Two clicks to reset tab content
button.click()
button.click()
return
if self._is_correct_tab_opened(tab):
return
else:
print(COLOR_FAIL + f"{tab_name} tab is not opened, will try again." + COLOR_ENDC)
sleeper.random_sleep()
else:
seconds_left = timer.get_seconds_left()
if seconds_left > 0:
Expand All @@ -194,6 +197,17 @@ def navigate_to(self, tab: TabBarTabs):

raise LanguageNotEnglishException()

def _is_correct_tab_opened(self, tab: TabBarTabs) -> bool:
if tab == TabBarTabs.HOME:
return HomeView(self.device).is_visible()
elif tab == TabBarTabs.SEARCH:
return SearchView(self.device).is_visible()
elif tab == TabBarTabs.PROFILE:
return ProfileView(self.device, is_own_profile=True).is_visible()
else:
# We can support more tabs' checks here
return True

def _get_top(self):
if self.top is None:
try:
Expand Down Expand Up @@ -271,9 +285,16 @@ def create_instance(device):


class HomeView(ActionBarView):
LOGO_ID = '{0}:id/action_bar_textview_custom_title_container'
LOGO_CLASS_NAME = 'android.widget.FrameLayout'

def __init__(self, device: DeviceFacade):
super().__init__(device)

def is_visible(self) -> bool:
return self.device.find(resourceId=self.LOGO_ID.format(self.device.app_id),
className=self.LOGO_CLASS_NAME).exists()

def navigate_to_search(self):
print_debug("Navigate to Search")
search_btn = self.action_bar.child(
Expand Down Expand Up @@ -326,6 +347,9 @@ class SearchView(InstagramView):
SEARCH_TEXT_ID = '{0}:id/echo_text'
SEARCH_TEXT_CLASSNAME = 'android.widget.TextView'

def is_visible(self) -> bool:
return self._get_search_edit_text().exists()

def refresh(self):
posts_grid = self.device.find(resourceId=PostsGridView.POSTS_GRID_RESOURCE_ID.format(self.device.app_id),
classNameMatches=PostsGridView.POSTS_GRID_CLASS_NAME)
Expand Down Expand Up @@ -859,6 +883,7 @@ class ProfileView(ActionBarView):
FOLLOWERS_BUTTON_ID_REGEX = '{0}:id/row_profile_header_followers_container|{1}:id/row_profile_header_container_followers'
FOLLOWING_BUTTON_ID_REGEX = '{0}:id/row_profile_header_following_container|{1}:id/row_profile_header_container_following'
MESSAGE_BUTTON_CLASS_NAME_REGEX = TEXTVIEW_OR_BUTTON_REGEX
USERNAME_REGEX = re.compile(r'[a-z0-9_-]+')

def __init__(self, device: DeviceFacade, is_own_profile=False):
super().__init__(device)
Expand Down Expand Up @@ -944,12 +969,17 @@ def _get_action_bar_title_btn(self):
resourceIdMatches=re_case_insensitive, className="android.widget.TextView"
)

def get_username(self, error=True):
def get_username(self):
title_view = self._get_action_bar_title_btn()
if title_view.exists():
return title_view.get_text()
if error:
print(COLOR_FAIL + "Cannot get username" + COLOR_ENDC)
username = title_view.get_text()
if self.USERNAME_REGEX.fullmatch(username) is not None:
return title_view.get_text()
else:
print(COLOR_FAIL + f"Username doesn't look like real username: {username}" + COLOR_ENDC)
return None

print(COLOR_FAIL + "Cannot get username" + COLOR_ENDC)
return None

def get_followers_count(self, swipe_up_if_needed=False) -> Optional[int]:
Expand Down Expand Up @@ -1374,15 +1404,21 @@ class DialogView(InstagramView):
LOCATION_CHECKBOX_ID_REGEX = '.*?:id/do_not_ask_checkbox'

def is_visible(self) -> bool:
dialog_v1 = self.device.find(resourceId=f'{self.device.app_id}:id/dialog_root_view',
dialog_v1 = self.device.find(resourceId=f'{self.device.app_id}:id/bottom_sheet_container',
className='android.widget.FrameLayout')
dialog_v2 = self.device.find(resourceId=f'{self.device.app_id}:id/dialog_root_view',
className='android.widget.FrameLayout')
dialog_v2 = self.device.find(resourceId=f'{self.device.app_id}:id/dialog_container',
dialog_v3 = self.device.find(resourceId=f'{self.device.app_id}:id/dialog_container',
classNameMatches='android.view.ViewGroup|android.view.View')
dialog_v3 = self.device.find(resourceId=f'{self.device.app_id}:id/content',
dialog_v4 = self.device.find(resourceId=f'{self.device.app_id}:id/content',
className='android.widget.FrameLayout')
dialog_v4 = self.device.find(resourceIdMatches='com.android.(permissioncontroller|packageinstaller):id/.*?',
dialog_v5 = self.device.find(resourceIdMatches='com.android.(permissioncontroller|packageinstaller):id/.*?',
className='android.widget.LinearLayout')
return dialog_v1.exists(quick=True) or dialog_v2.exists(quick=True) or dialog_v3.exists(quick=True) or dialog_v4.exists(quick=True)
return dialog_v1.exists(quick=True) \
or dialog_v2.exists(quick=True) \
or dialog_v3.exists(quick=True) \
or dialog_v4.exists(quick=True) \
or dialog_v5.exists(quick=True)

def click_unfollow(self) -> bool:
unfollow_button = self.device.find(
Expand Down

0 comments on commit 9848fe1

Please sign in to comment.