Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix Release v1.2.3 #168

Merged
merged 10 commits into from
Jan 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
General fixes (#161)
- introduced a crash when double click fail (entering in location maybe? in that case it will do a device back so the bot won't restart)
- tuned the double click duration (0.050-0.170)
- add a sleep after the click on profile picture to watch stories to prevent a crash
- using existing resourceID, and remove classID when not needed
- if go_back: was in a bad position(hashtag_likers.py)
- introduced a new click mode: click until element gone, return a bool. Not used yet
- case insensitive match for searching in search tab
  • Loading branch information
mastrolube authored Dec 25, 2020
commit 578994ce4b006b5a85934cb0d239d32aaf4badfb
13 changes: 12 additions & 1 deletion GramAddict/core/device_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ def down(self, *args, **kwargs):
raise DeviceFacade.JsonRpcError(e)
return DeviceFacade.View(version=2, view=view, device=self.deviceV2)

def click_gone(self, maxretry=3, interval=1.0):
if self.viewV1 is not None:
DeviceFacade.View.click(device=self.deviceV1)
else:
import uiautomator2

try:
self.viewV2.click_gone(maxretry, interval)
except uiautomator2.JSONRPCError as e:
raise DeviceFacade.JsonRpcError(e)

def click(self, mode=None):
if self.viewV1 is not None:
import uiautomator
Expand Down Expand Up @@ -534,7 +545,7 @@ def double_click(self, padding=0.3, obj_over=0):
visible_bounds["bottom"] - vertical_padding,
)
)
time_between_clicks = uniform(0.050, 0.200)
time_between_clicks = uniform(0.050, 0.170)

try:
logger.debug(
Expand Down
4 changes: 3 additions & 1 deletion GramAddict/core/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ def _watch_stories(
if profile_view.isStoryAvailable():
profile_picture = profile_view.profileImage()
if profile_picture.exists():
profile_picture.click() # Open the first story
logger.debug("Open the first story")
profile_picture.click()
random_sleep(1, 2)
on_watch()
random_sleep()

Expand Down
29 changes: 12 additions & 17 deletions GramAddict/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def _getUsernameRow(self, username):
return self.device.find(
resourceIdMatches=case_insensitive_re(ResourceID.ROW_SEARCH_USER_USERNAME),
className=ClassName.TEXT_VIEW,
text=username,
textMatches=case_insensitive_re(username),
)

def _getHashtagRow(self, hashtag):
Expand Down Expand Up @@ -743,26 +743,25 @@ def _getPostLikeButton(self, scroll_to_find=True):
scroll_to_find: if the like button is not found, scroll a bit down
to try to find it. Default: True
"""
media_group = case_insensitive_re(
[
ResourceID.MEDIA_GROUP,
ResourceID.CAROUSEL_MEDIA_GROUP,
]
)
post_view_area = self.device.find(
resourceIdMatches=case_insensitive_re(ResourceID.LIST)
)
if not post_view_area.exists():
logger.debug("Cannot find post recycler view area")
save_crash(self.device)
self.device.back()
return None

post_media_view = self.device.find(
resourceIdMatches=media_group,
className=ClassName.FRAME_LAYOUT,
resourceIdMatches=case_insensitive_re(
ResourceID.CAROUSEL_MEDIA_GROUP_AND_ZOOMABLE_VIEW_CONTAINER
)
)

if not post_media_view.exists():
logger.debug("Cannot find post media view area")
save_crash(self.device)
self.device.back()
return None

like_btn_view = post_media_view.down(
Expand Down Expand Up @@ -822,14 +821,10 @@ def _isPostLiked(self):
return like_btn_view.get_selected()

def likePost(self, click_btn_like=False):
media_group = case_insensitive_re(
[
ResourceID.MEDIA_GROUP,
ResourceID.CAROUSEL_MEDIA_GROUP,
]
)
post_media_view = self.device.find(
resourceIdMatches=media_group, className=ClassName.FRAME_LAYOUT
resourceIdMatches=case_insensitive_re(
ResourceID.CAROUSEL_MEDIA_GROUP_AND_ZOOMABLE_VIEW_CONTAINER
)
)

if click_btn_like:
Expand All @@ -838,7 +833,6 @@ def likePost(self, click_btn_like=False):
return False
like_btn_view.click()
else:

if post_media_view.exists(True):
post_media_view.double_click()
else:
Expand Down Expand Up @@ -903,6 +897,7 @@ def navigateToPost(self, row, col):
if not post_view.exists():
return None
post_view.click()
# post_view.click_gone()

return OpenedPostView(self.device)

Expand Down
23 changes: 11 additions & 12 deletions GramAddict/plugins/interact_hashtag_likers.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ def handle_hashtag(
PostsViewList(device).swipe_to_fit_posts(SwipeTo.NEXT_POST)
continue

logger.info("Open list of likers.")
posts_end_detector.notify_new_page()
random_sleep()

Expand Down Expand Up @@ -336,6 +335,17 @@ def handle_hashtag(
extra={"color": f"{Fore.GREEN}"},
)
go_back = True
if go_back:
prev_screen_iterated_likers.clear()
prev_screen_iterated_likers += screen_iterated_likers
logger.info(
f"Back to {hashtag}'s posts list.",
extra={"color": f"{Fore.GREEN}"},
)
device.back()
logger.info("Going to the next post.")
PostsViewList(device).swipe_to_fit_posts(SwipeTo.NEXT_POST)
break
if posts_end_detector.is_fling_limit_reached():
prev_screen_iterated_likers.clear()
prev_screen_iterated_likers += screen_iterated_likers
Expand All @@ -352,17 +362,6 @@ def handle_hashtag(
extra={"color": f"{Fore.GREEN}"},
)
likes_list_view.scroll(DeviceFacade.Direction.BOTTOM)
if go_back:
prev_screen_iterated_likers.clear()
prev_screen_iterated_likers += screen_iterated_likers
logger.info(
f"Back to {hashtag}'s posts list.",
extra={"color": f"{Fore.GREEN}"},
)
device.back()
logger.info("Going to the next post.")
PostsViewList(device).swipe_to_fit_posts(SwipeTo.NEXT_POST)
break

if posts_end_detector.is_the_end():
break