From 9f102261d6ac520cb53390f4629b11aa67a49e74 Mon Sep 17 00:00:00 2001 From: sexnine Date: Mon, 25 Jan 2021 12:55:10 +1100 Subject: [PATCH] Update login.py Adds support for logging in with mobile authenticator. Uses Chrome driver path from config now. Cleaned up code a bit. --- login.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/login.py b/login.py index 00657da..c52adb3 100644 --- a/login.py +++ b/login.py @@ -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!")