MCPcopy
hub / github.com/InstaPy/InstaPy / check_authorization

Function check_authorization

instapy/util.py:1616–1674  ·  view source on GitHub ↗

Check if user is NOW logged in

(browser, username, method, logger, notify=True)

Source from the content-addressed store, hash-verified

1614
1615
1616def check_authorization(browser, username, method, logger, notify=True):
1617 """Check if user is NOW logged in"""
1618 if notify is True:
1619 logger.info("Checking if '{}' is logged in...".format(username))
1620
1621 # different methods can be added in future
1622 if method == "activity counts":
1623
1624 # navigate to owner's profile page only if it is on an unusual page
1625 current_url = get_current_url(browser)
1626 if (
1627 not current_url
1628 or "https://www.instagram.com" not in current_url
1629 or "https://www.instagram.com/graphql/" in current_url
1630 ):
1631 profile_link = "https://www.instagram.com/{}/".format(username)
1632 web_address_navigator(browser, profile_link)
1633
1634 # if user is not logged in, `activity_counts` will be `None`- JS `null`
1635 try:
1636 activity_counts = browser.execute_script(
1637 "return window._sharedData.activity_counts"
1638 )
1639
1640 except WebDriverException:
1641 try:
1642 browser.execute_script("location.reload()")
1643 update_activity(browser, state=None)
1644
1645 activity_counts = browser.execute_script(
1646 "return window._sharedData.activity_counts"
1647 )
1648
1649 except WebDriverException:
1650 activity_counts = None
1651
1652 # if user is not logged in, `activity_counts_new` will be `None`- JS
1653 # `null`
1654 try:
1655 activity_counts_new = browser.execute_script(
1656 "return window._sharedData.config.viewer"
1657 )
1658
1659 except WebDriverException:
1660 try:
1661 browser.execute_script("location.reload()")
1662 activity_counts_new = browser.execute_script(
1663 "return window._sharedData.config.viewer"
1664 )
1665
1666 except WebDriverException:
1667 activity_counts_new = None
1668
1669 if activity_counts is None and activity_counts_new is None:
1670 if notify is True:
1671 logger.critical("--> '{}' is not logged in!\n".format(username))
1672 return False
1673

Callers 3

login_userFunction · 0.85
emergency_exitFunction · 0.85

Calls 4

get_current_urlFunction · 0.85
web_address_navigatorFunction · 0.85
update_activityFunction · 0.85
execute_scriptMethod · 0.80

Tested by

no test coverage detected