From 78ecf561eb41c094f1d506947a095fed040dd301 Mon Sep 17 00:00:00 2001 From: 0xil0rphan <0xil0rphan@protonmail.ch> Date: Tue, 2 Feb 2021 21:02:33 -0500 Subject: [PATCH 1/2] Added a function to retrieve information about the launched Chrome browser. This info is exceptionally useful when debugging so that users can easily see how their Chrome instance is set up, what version is in use, where it is saving data to disk, among other things. --- stores/amazon.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/stores/amazon.py b/stores/amazon.py index b56d7ba4..999ae583 100644 --- a/stores/amazon.py +++ b/stores/amazon.py @@ -41,7 +41,7 @@ from utils import discord_presence as presence from utils.debugger import debug from utils.logger import log -from utils.selenium_utils import options, enable_headless +from utils.selenium_utils import options, enable_headless, By, ec # Optional OFFER_URL is: "OFFER_URL": "https://{domain}/dp/", AMAZON_URLS = { @@ -1442,6 +1442,62 @@ def show_config(self): log.warning(f"--Testing Mode. NO Purchases will be made.") log.info(f"{'=' * 50}") + def get_chromedriver_info(self): + try: + chrome_instance_info_url = "chrome://version" + self.driver.get(url=chrome_instance_info_url) + logo_found = self.wait.until(ec.presence_of_element_located((By.ID, "logo"))) # Wait for chrome logo to be put on page before parsing html. + except Exception as e: + log.warning(e) + log.warning(f"Couldnt get Chrome information... Continuing on...") + return + try: + version = self.driver.find_element_by_id("version") + log.info(f"Google Chrome Version:\t{version.text}") + except Exception as e: + log.warning(e) + try: + revision = self.driver.find_element_by_xpath('//*[@id="inner"]/tbody/tr[2]/td[2]/span') + log.info(f"Revision:\t\t\t{revision.text}") + except Exception as e: + log.warning(e) + try: + os_type = self.driver.find_element_by_id("os_type") + log.info(f"OS:\t\t\t\t{os_type.text}") + except Exception as e: + log.warning(e) + try: + js_engine = self.driver.find_element_by_id("js_engine") + log.info(f"JS Engine:\t\t\t{js_engine.text}") + except Exception as e: + log.warning(e) + try: + flash_version = self.driver.find_element_by_id("flash_version") + log.info(f"Flash Version:\t\t{flash_version.text}") + except Exception as e: + log.warning(e) + try: + user_agent = self.driver.find_element_by_id("useragent") + log.info(f"User Agent:\t\t\t{user_agent.text}") + except Exception as e: + log.warning(e) + try: + command_line = self.driver.find_element_by_id("command_line") + log.info(f"Process Command:\t\t{command_line.text}") + except Exception as e: + log.warning(e) + try: + executable_path = self.driver.find_element_by_id("executable_path") + log.info(f"Executable Path:\t\t{executable_path.text}") + except Exception as e: + log.warning(e) + try: + profile_path = self.driver.find_element_by_id("profile_path") + log.info(f"Profile Path:\t\t{profile_path.text}") + except Exception as e: + log.warning(e) + return + def create_driver(self, path_to_profile): if self.setup_driver: @@ -1479,6 +1535,7 @@ def create_driver(self, path_to_profile): self.driver = webdriver.Chrome(executable_path=binary_path, options=options) self.wait = WebDriverWait(self.driver, 10) self.get_webdriver_pids() + self.get_chromedriver_info() except Exception as e: log.error(e) log.error( From b599b3b44f880546890a6eee4f4ed8b7d20f9eda Mon Sep 17 00:00:00 2001 From: DakkJaniels <6080734+DakkJaniels@users.noreply.github.com> Date: Tue, 2 Feb 2021 21:46:33 -0500 Subject: [PATCH 2/2] fixed black formatting --- app.py | 1 + stores/amazon.py | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index 9fa07dcd..8dc8ea53 100644 --- a/app.py +++ b/app.py @@ -30,6 +30,7 @@ def sha256sum(filename): h.update(mv[:n]) return h.hexdigest() + if os.path.exists("LICENSE") and sha256sum("LICENSE") in license_hash: s = """ FairGame Copyright (C) 2021 Hari Nagarajan diff --git a/stores/amazon.py b/stores/amazon.py index 999ae583..79cfc5c4 100644 --- a/stores/amazon.py +++ b/stores/amazon.py @@ -505,7 +505,9 @@ def check_stock(self, asin, reserve_min, reserve_max, retry=0): # Sanity check to see if we have any offers try: # Wait for the page to load before determining what's in it by looking for the footer - footer: WebElement = WebDriverWait(self.driver, timeout=DEFAULT_MAX_TIMEOUT).until( + footer: WebElement = WebDriverWait( + self.driver, timeout=DEFAULT_MAX_TIMEOUT + ).until( lambda d: d.find_elements_by_xpath( "//div[@class='nav-footer-line'] | //img[@alt='Dogs of Amazon']" ) @@ -1435,9 +1437,7 @@ def show_config(self): if not self.notification_handler.sound_enabled: log.info(f"--Notification sounds are disabled.") if self.headless: - log.warning( - f"--Running in headless mode." - ) + log.warning(f"--Running in headless mode.") if self.testing: log.warning(f"--Testing Mode. NO Purchases will be made.") log.info(f"{'=' * 50}") @@ -1445,19 +1445,23 @@ def show_config(self): def get_chromedriver_info(self): try: chrome_instance_info_url = "chrome://version" - self.driver.get(url=chrome_instance_info_url) - logo_found = self.wait.until(ec.presence_of_element_located((By.ID, "logo"))) # Wait for chrome logo to be put on page before parsing html. + self.driver.get(url=chrome_instance_info_url) + logo_found = self.wait.until( + ec.presence_of_element_located((By.ID, "logo")) + ) # Wait for chrome logo to be put on page before parsing html. except Exception as e: log.warning(e) log.warning(f"Couldnt get Chrome information... Continuing on...") return - try: + try: version = self.driver.find_element_by_id("version") log.info(f"Google Chrome Version:\t{version.text}") except Exception as e: log.warning(e) try: - revision = self.driver.find_element_by_xpath('//*[@id="inner"]/tbody/tr[2]/td[2]/span') + revision = self.driver.find_element_by_xpath( + '//*[@id="inner"]/tbody/tr[2]/td[2]/span' + ) log.info(f"Revision:\t\t\t{revision.text}") except Exception as e: log.warning(e)