Skip to content

Instantly share code, notes, and snippets.

@uluQulu
Created August 23, 2018 01:07
Show Gist options
  • Save uluQulu/3be8d7a4b52379e3e1dc1fd884cb4578 to your computer and use it in GitHub Desktop.
Save uluQulu/3be8d7a4b52379e3e1dc1fd884cb4578 to your computer and use it in GitHub Desktop.
Emergency exit if there is a serious situation
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