Created
August 23, 2018 01:07
-
-
Save uluQulu/3be8d7a4b52379e3e1dc1fd884cb4578 to your computer and use it in GitHub Desktop.
Emergency exit if there is a serious situation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def emergency_exit(browser, username, logger): | |
""" Raise emergency if the is no connection to server OR user is not logged in """ | |
# ping server | |
connection_state = ping_server("instagram.com") | |
if connection_state == False: | |
logger.error("{} is not connected to the server!".format(username)) | |
return True | |
else: | |
profile_link = 'https://www.instagram.com/{}/'.format(username) | |
web_adress_navigator(browser, profile_link) | |
# check if we are now logged in | |
try: | |
valid_connection = browser.execute_script( | |
"return window._sharedData.activity_counts") | |
except WebDriverException: | |
try: | |
browser.execute_script("location.reload()") | |
valid_connection = browser.execute_script( | |
"return window._sharedData.activity_counts") | |
except WebDriverException: | |
valid_connection = False | |
if not valid_connection: | |
logger.error("--> {} is not logged in!\n".format(username)) | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment