Skip to content

Commit

Permalink
Update login.py
Browse files Browse the repository at this point in the history
Adds support for logging in with mobile authenticator.
Uses Chrome driver path from config now.
Cleaned up code a bit.
  • Loading branch information
sexnine committed Jan 25, 2021
1 parent d784159 commit 9f10226
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions login.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
import yaml
import pickle
from selenium import webdriver
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe")

config = None

# Yes this was copy pasted was stack overflow because I couldn't be fucked to understand how to do it myself lmao
class wait_for_the_attribute_value(object):
def __init__(self, locator, attribute, value):
self.locator = locator
self.attribute = attribute
self.value = value

def load_config():
print("Loading config")
with open("config.yml", "r") as f:
global config
config = yaml.safe_load(f)
print("Loaded config!")


class CheckLoggedIn(object):
def __call__(self, driver):
if driver.current_url.startswith("https://steamcommunity.com/id/"):
return True
try:
element_attribute = EC._find_element(driver, self.locator).get_attribute(self.attribute)
return element_attribute == self.value
return driver.find_element_by_id("auth_message_success").get_attribute("style") == ""
except StaleElementReferenceException:
return False


def main():
load_config()
driver = webdriver.Chrome(config.get("driver_file_path", "chromedriver.exe"))
driver.get("https://steamcommunity.com/login/")
print("Please sign into Steam, you have 180 seconds to do so.")

try:
WebDriverWait(driver, timeout=180, poll_frequency=1).until(wait_for_the_attribute_value((By.ID, "auth_message_success"), "style", ""))
WebDriverWait(driver, timeout=180, poll_frequency=1).until(CheckLoggedIn())
except TimeoutException:
print("You took too long to sign in (180 seconds)")
print("Signed in!")
Expand Down

0 comments on commit 9f10226

Please sign in to comment.