Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion GramAddict/core/device_facade.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import string
import time
from datetime import datetime
from enum import Enum, auto
from inspect import stack
Expand All @@ -12,7 +13,7 @@

import uiautomator2

from GramAddict.core.utils import random_sleep
from GramAddict.core.utils import random_sleep, wait_for_element

logger = logging.getLogger(__name__)

Expand Down
27 changes: 19 additions & 8 deletions GramAddict/core/handle_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
UniversalActions,
case_insensitive_re,
)
from uiautomator2.exceptions import UiObjectNotFoundError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -715,14 +716,23 @@ def scrolled_to_top():
return row_search.exists()

while True:
logger.info("Iterate over visible followers.")
screen_iterated_followers = []
screen_skipped_followers_count = 0
scroll_end_detector.notify_new_page()
user_list = device.find(
resourceIdMatches=self.ResourceID.USER_LIST_CONTAINER,
)
row_height, n_users = inspect_current_view(user_list)
try:
logger.info("Iterate over visible followers.")
screen_iterated_followers = []
screen_skipped_followers_count = 0
scroll_end_detector.notify_new_page()
user_list = device.find(
resourceIdMatches=self.ResourceID.USER_LIST_CONTAINER,
)
row_height, n_users = inspect_current_view(user_list)
except UiObjectNotFoundError:
logger.info(
"Unable to find USER_LIST_CONTAINER elements, clicking on the back button again",
extra={"color": f"{Fore.RED}"},
)
device.back()
continue

try:
for item in user_list:
cur_row_height = item.get_height()
Expand Down Expand Up @@ -792,6 +802,7 @@ def scrolled_to_top():
extra={"color": f"{Fore.GREEN}"},
)


if is_myself and scrolled_to_top():
logger.info("Scrolled to top, finish.", extra={"color": f"{Fore.GREEN}"})
return
Expand Down
26 changes: 14 additions & 12 deletions GramAddict/core/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,20 @@ def nav_to_hashtag_or_place(device, target, current_job):

TargetView = HashTagView if current_job.startswith("hashtag") else PlacesView

if current_job.endswith("recent"):
logger.info("Switching to Recent tab.")
recent_tab = TargetView(device)._getRecentTab()
if recent_tab.exists(Timeout.MEDIUM):
recent_tab.click()
else:
return False

if UniversalActions(device)._check_if_no_posts():
UniversalActions(device)._reload_page()
if UniversalActions(device)._check_if_no_posts():
return False
# when searching for a hashtag, the recent tab is not available anymore in version 263.2.0.19.104

# if current_job.endswith("recent"):
# logger.info("Switching to Recent tab.")
# recent_tab = TargetView(device)._getRecentTab()
# if recent_tab.exists(Timeout.MEDIUM):
# recent_tab.click()
# else:
# return False
#
# if UniversalActions(device)._check_if_no_posts():
# UniversalActions(device)._reload_page()
# if UniversalActions(device)._check_if_no_posts():
# return False

result_view = TargetView(device)._getRecyclerView()
FistImageInView = TargetView(device)._getFistImageView(result_view)
Expand Down
9 changes: 9 additions & 0 deletions GramAddict/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,15 @@ def inspect_current_view(user_list) -> Tuple[int, int]:
logger.debug(f"There are {n_users} users fully visible in that view.")
return row_height, n_users

# used by back function device_facade.py - attempt to fix bug #367
def wait_for_element(device, selector, timeout=15):
end_time = time.time() + timeout
while time.time() < end_time:
if device(**selector).exists:
return True
time.sleep(1)
return False


class ActionBlockedError(Exception):
pass
Expand Down
5 changes: 5 additions & 0 deletions GramAddict/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,11 @@ def detect_media_type(content_desc) -> Tuple[Optional[MediaType], Optional[int]]
)
obj_count = n_photos + n_videos
media_type = MediaType.CAROUSEL
# workaround test for bug #285/#301
if obj_count == 0:
media_type = MediaType.REEL # it might be better to set it to UNKNOWN
logger.info("Activating workaround test for Bug #285 - switching to REEL media type")
# end of workaround test
return media_type, obj_count

def _like_in_post_view(
Expand Down