Skip to content

Commit

Permalink
Added _nav_explore() method; Fixed _login_required() decorator.
Browse files Browse the repository at this point in the history
_nav_explore() -> navigates to the explore page and checks whether the operation was successful

-login_required() -> FIxed a bug where the client would try to log in again even if client is already logged in.
  • Loading branch information
davidwickerhf committed Jan 10, 2021
1 parent 0887e9c commit 79b57b8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
2 changes: 2 additions & 0 deletions instaclient/client/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ def login(self:'InstaClient', username:str, password:str, check_user:bool=True)
if not_now:
not_now = self._find_element(EC.presence_of_element_located((By.XPATH, Paths.NOT_NOW_INFO_BTN)))
self._press_button(not_now)
LOGGER.debug('Dismissed Dialogue')

not_now = self._check_existence(EC.presence_of_element_located((By.XPATH, Paths.NOT_NOW_BTN)))
if not_now:
not_now = self._find_element(EC.presence_of_element_located((By.XPATH, Paths.NOT_NOW_BTN)))
self._press_button(not_now)
LOGGER.debug('Dismissed Dialogue')
return self.logged_in


Expand Down
11 changes: 11 additions & 0 deletions instaclient/client/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def is_valid_user(self:'InstaClient', user:str) -> bool:

@Component._driver_required
def _is_valid_page(self:'InstaClient', url:str=None):
"""Checks if a page is valid.
Args:
url (str, optional): Expected current url. Defaults to None.
Returns:
bool: True if the current page exists and is loaded.
False if the current url doesn\'t match the expected
url or if a PAGE NOT FOUND warning is showed
on the page itself.
"""
current = self.driver.current_url
if url:
if url != current:
Expand Down
9 changes: 5 additions & 4 deletions instaclient/client/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ def wrapper(self: 'InstaClient', *args, **kwargs):
if self.username is None or self.password is None:
raise NotLoggedInError()

if not self.driver:
self.connect(True, func=func.__name__)
else:
self.login(self.username, self.password)
if not self.logged_in:
if not self.driver:
self.connect(True, func=func.__name__)
else:
self.login(self.username, self.password)

error = False
result = None
Expand Down
1 change: 1 addition & 0 deletions instaclient/client/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class ClientUrls:
DM_URL = 'https://www.instagram.com/direct/t/'
POST_URL = 'https://www.instagram.com/p/{}/'
COMMENTS_URL = 'https://www.instagram.com/p/{}/comments/'
EXPLORE_PAGE = 'https://www.instagram.com/explore/'


class GraphUrls:
Expand Down
2 changes: 1 addition & 1 deletion instaclient/client/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def scroll(self, mode=PAGE_DOWN_SCROLL, size:int=500, times:int=1, interval:int=
url = self.driver.current_url
body = self._find_element(EC.presence_of_element_located((By.TAG_NAME, 'body')), retry=True, url=url)
body.send_keys(Keys.END)

time.sleep(interval)
LOGGER.info('Scrolled')
return False


Expand Down
12 changes: 10 additions & 2 deletions instaclient/client/navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ def _nav_post_comments(self:'InstaClient', shortcode:str):


def _nav_tag(self:'InstaClient', tag:str):
"""
Naviagtes to a search for posts with a specific tag on IG.
"""Navigates to a search for posts with a specific tag on IG.
Args:
tag:str: Tag to search for
Expand All @@ -132,3 +131,12 @@ def _nav_tag(self:'InstaClient', tag:str):
else:
# Operation Successful
return True


def _nav_explore(self:'InstaClient'):
"""Navigates to the explore page
"""
self.driver.get(ClientUrls.EXPLORE_PAGE)
if self._is_valid_page(ClientUrls.EXPLORE_PAGE):
return True
return False

0 comments on commit 79b57b8

Please sign in to comment.