def login(self): try: log.info("Email") self.driver.find_element_by_xpath('//*[@id="ap_email"]').send_keys( self.username + Keys.RETURN) except: log.info("Email not needed.") pass if self.driver.find_elements_by_xpath( '//*[@id="auth-error-message-box"]'): log.error( "Login failed, check your username in amazon_config.json") time.sleep(240) exit(1) log.info("Remember me checkbox") selenium_utils.button_click_using_xpath(self.driver, '//*[@name="rememberMe"]') log.info("Password") self.driver.find_element_by_xpath('//*[@id="ap_password"]').send_keys( self.password + Keys.RETURN) log.info(f"Logged in as {self.username}")
def __init__(self, notification_handler, headless=False): self.notification_handler = notification_handler if headless: enable_headless() options.add_argument(f"user-data-dir=.profile-amz") try: self.driver = webdriver.Chrome(executable_path=binary_path, options=options) self.wait = WebDriverWait(self.driver, 10) except SessionNotCreatedException as e: log.error(e) exit(1) except Exception as e: log.error(e) if path.exists(AUTOBUY_CONFIG_PATH): with open(AUTOBUY_CONFIG_PATH) as json_file: try: config = json.load(json_file) self.username = config["username"] self.password = config["password"] self.asin_list = config["asin_list"] self.reserve = float(config["reserve"]) self.amazon_website = config.get("amazon_website", "smile.amazon.com") assert isinstance(self.asin_list, list) except Exception: log.error( "amazon_config.json file not formatted properly: https://github.com/Hari-Nagarajan/nvidia-bot/wiki/Usage#json-configuration" ) exit(0) else: log.error( "No config file found, see here on how to fix this: https://github.com/Hari-Nagarajan/nvidia-bot/wiki/Usage#json-configuration" ) exit(0) for key in AMAZON_URLS.keys(): AMAZON_URLS[key] = AMAZON_URLS[key].format( domain=self.amazon_website) self.driver.get(AMAZON_URLS["BASE_URL"]) log.info("Waiting for home page.") self.check_if_captcha(self.wait_for_pages, HOME_PAGE_TITLES) if self.is_logged_in(): log.info("Already logged in") else: log.info("Lets log in.") is_smile = "smile" in AMAZON_URLS["BASE_URL"] xpath = '//*[@id="ge-hello"]/div/span/a' if is_smile else '//*[@id="nav-link-accountList"]/div/span' selenium_utils.button_click_using_xpath(self.driver, xpath) log.info("Wait for Sign In page") self.check_if_captcha(self.wait_for_pages, SIGN_IN_TITLES) self.login() log.info("Waiting 15 seconds.") time.sleep( 15 ) # We can remove this once I get more info on the phone verification page.
def address_validation_page(self): try: selenium_utils.wait_for_page( self.driver, PAGE_TITLES_BY_LOCALE[self.locale]["address_validation"], 5, ) log.debug("Setting suggested shipping information.") selenium_utils.wait_for_element( self.driver, "billingAddressOptionRow2").click() selenium_utils.button_click_using_xpath( self.driver, "//input[@id='selectionButton']") except TimeoutException: log.error("Address validation not required?")
def __init__(self, headless=False): self.notification_handler = NotificationHandler() if headless: enable_headless() options.add_argument(f"user-data-dir=.profile-amz") self.driver = webdriver.Chrome(executable_path=binary_path, options=options) self.wait = WebDriverWait(self.driver, 10) if path.exists(AUTOBUY_CONFIG_PATH): with open(AUTOBUY_CONFIG_PATH) as json_file: try: config = json.load(json_file) self.username = config["username"] self.password = config["password"] self.asin_list = config["asin_list"] self.amazon_website = config.get("amazon_website", "amazon.com") assert isinstance(self.asin_list, list) except Exception: raise InvalidAutoBuyConfigException( "amazon_config.json file not formatted properly.") else: raise InvalidAutoBuyConfigException( "Missing amazon_config.json file.") for key in AMAZON_URLS.keys(): AMAZON_URLS[key] = AMAZON_URLS[key].format(self.amazon_website) print(AMAZON_URLS) self.driver.get(AMAZON_URLS["BASE_URL"]) log.info("Waiting for home page.") self.check_if_captcha(self.wait_for_pages, HOME_PAGE_TITLES) if self.is_logged_in(): log.info("Already logged in") else: log.info("Lets log in.") selenium_utils.button_click_using_xpath( self.driver, '//*[@id="nav-link-accountList"]/div/span') log.info("Wait for Sign In page") self.check_if_captcha(self.wait_for_pages, SIGN_IN_TITLES) self.login() log.info("Waiting 15 seconds.") time.sleep( 15 ) # We can remove this once I get more info on the phone verification page.
def login(self): try: log.info("Email") self.driver.find_element_by_xpath('//*[@id="ap_email"]').send_keys( self.username + Keys.RETURN) except: log.info("Email not needed.") pass log.info("Remember me checkbox") selenium_utils.button_click_using_xpath(self.driver, '//*[@name="rememberMe"]') log.info("Password") self.driver.find_element_by_xpath('//*[@id="ap_password"]').send_keys( self.password + Keys.RETURN) log.info(f"Logged in as {self.username}")
def buy(self, delay=5, test=False, model=""): selector = '//a[@id="LFrame_btnAddToCart"]' associate_code = "&associatecode=2QME1VF65K9ZY8B" if test: model_name = "test" url = "https://www.evga.com/products/product.aspx?pn=08G-P4-3289-KR" self.driver.get(url + associate_code) selenium_utils.wait_for_page( self.driver, "EVGA - Products - EVGA GeForce RTX 2080 SUPER FTW3 HYDRO COPPER GAMING, 08G-P4-3289-KR, 8GB GDDR6, RGB LED, iCX2 Technology, Metal Backplate - 08G-P4-3289-KR", ) else: models = { "ftw3": [ "https://www.evga.com/products/product.aspx?pn=10G-P5-3895-KR", "EVGA - Products - EVGA GeForce RTX 3080 FTW3 GAMING, 10G-P5-3895-KR, 10GB GDDR6X, iCX3 Technology, ARGB LED, Metal Backplate - 10G-P5-3895-KR", ], "xc3": [ "https://www.evga.com/products/product.aspx?pn=10G-P5-3883-KR", "EVGA - Products - EVGA GeForce RTX 3080 XC3 GAMING, 10G-P5-3883-KR, 10GB GDDR6X, iCX3 Cooling, ARGB LED, Metal Backplate - 10G-P5-3883-KR", ], "xc3ultra": [ "https://www.evga.com/products/product.aspx?pn=10G-P5-3885-KR", "EVGA - Products - EVGA GeForce RTX 3080 XC3 ULTRA GAMING, 10G-P5-3885-KR, 10GB GDDR6X, iCX3 Cooling, ARGB LED, Metal Backplate - 10G-P5-3885-KR", ], "xc3black": [ "https://www.evga.com/products/product.aspx?pn=10G-P5-3881-KR", "EVGA - Products - EVGA GeForce RTX 3080 XC3 BLACK GAMING, 10G-P5-3881-KR, 10GB GDDR6X, iCX3 Cooling, ARGB LED - 10G-P5-3881-KR", ], "ftw3ultra": [ "https://www.evga.com/products/product.aspx?pn=10G-P5-3897-KR", "EVGA - Products - EVGA GeForce RTX 3080 FTW3 ULTRA GAMING, 10G-P5-3897-KR, 10GB GDDR6X, iCX3 Technology, ARGB LED, Metal Backplate - 10G-P5-3897-KR", ], "any": [ "https://www.evga.com/products/productlist.aspx?type=0&family=GeForce+30+Series+Family&chipset=RTX+3080", "EVGA - Products - Graphics - GeForce 30 Series Family - RTX 3080", ], } if model: self.driver.get(models[model][0] + associate_code) selenium_utils.wait_for_page(self.driver, models[model][1]) else: model = "any" selector = '//input[@class="btnBigAddCart"]' self.driver.get(models["any"][0] + associate_code) selenium_utils.wait_for_page(self.driver, models["any"][1]) # Check for stock log.info("On GPU Page") atc_buttons = self.driver.find_elements_by_xpath(selector) while not atc_buttons: if self.driver.current_url == models[model][0] + associate_code: log.debug("Refreshing page for " + model) self.driver.refresh() else: log.debug("Error page detected. Redirecting...") self.driver.get(models[model][0] + associate_code) atc_buttons = self.driver.find_elements_by_xpath(selector) sleep(delay) # send notification self.notification_handler.send_notification( f"EVGA BOT: " + model_name + " in stock! Attempting to place order...") # Add to cart atc_buttons[0].click() # Go to checkout selenium_utils.wait_for_page(self.driver, "EVGA - Checkout") selenium_utils.button_click_using_xpath( self.driver, '//*[@id="LFrame_CheckoutButton"]') # Shipping Address screen selenium_utils.wait_for_page(self.driver, "Shopping") log.info("Skip that page.") self.driver.get("https://secure.evga.com/Cart/Checkout_Payment.aspx") selenium_utils.wait_for_page(self.driver, "EVGA - Checkout - Billing Options") log.info("Ensure that we are paying with credit card") sleep(1) # Fix this. WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable( (By.XPATH, './/input[@value="rdoCreditCard"]'))).click() WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable( (By.XPATH, '//*[@id="ctl00_LFrame_btncontinue"]'))).click() selenium_utils.wait_for_element(self.driver, "ctl00_LFrame_txtNameOnCard") log.info("Populate credit card fields") selenium_utils.field_send_keys(self.driver, "ctl00$LFrame$txtNameOnCard", self.credit_card["name"]) selenium_utils.field_send_keys(self.driver, "ctl00$LFrame$txtCardNumber", self.credit_card["number"]) selenium_utils.field_send_keys(self.driver, "ctl00$LFrame$txtCvv", self.credit_card["cvv"]) Select(self.driver.find_element_by_id( "ctl00_LFrame_ddlMonth")).select_by_value( self.credit_card["expiration_month"]) Select(self.driver.find_element_by_id( "ctl00_LFrame_ddlYear")).select_by_value( self.credit_card["expiration_year"]) WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable(( By.XPATH, "/html/body/form/div[3]/div[3]/div/div[1]/div[5]/div[3]/div/div[1]/div/div[@id='checkoutButtons']/input[2]", ))).click() log.info("Finalize Order Page") selenium_utils.wait_for_page(self.driver, "EVGA - Checkout - Finalize Order") WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable( (By.ID, "ctl00_LFrame_cbAgree"))).click() selenium_utils.wait_for_element(self.driver, "ctl00_LFrame_btncontinue") if not test: WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable( (By.ID, "ctl00_LFrame_btncontinue"))).click() log.info("Finalized Order!")
def buy(self, delay=5, test=False): if test: log.info("Refreshing Page Until Title Matches ...") selenium_utils.wait_for_title( self.driver, "EVGA - Products - Graphics - GeForce 16 Series Family - GTX 1660", "https://www.evga.com/products/ProductList.aspx?type=0&family=GeForce+16+Series+Family&chipset=GTX+1660", ) else: log.info("Refreshing Page Until Title Matches ...") selenium_utils.wait_for_title( self.driver, "EVGA - Products - Graphics - GeForce 30 Series Family - RTX " + self.card_series, "https://www.evga.com/products/productlist.aspx?type=0&family=GeForce+30+Series+Family&chipset=RTX+" + self.card_series, ) log.info("matched chipset=RTX+" + self.card_series + "!") if self.card_pn and not test: # check for card log.info("On GPU list Page") card_btn = self.driver.find_elements_by_xpath( "//a[@href='/products/product.aspx?pn=" + self.card_pn + "']") while not card_btn: log.debug("Refreshing page for GPU") self.driver.refresh() card_btn = self.driver.find_elements_by_xpath( "//a[@href='/products/product.aspx?pn=" + self.card_pn + "']") sleep(delay) card_btn[0].click() # Check for stock log.info("On GPU Page") atc_buttons = self.driver.find_elements_by_xpath( '//input[@class="btnBigAddCart"]') while not atc_buttons: log.debug("Refreshing page for GPU") self.driver.refresh() atc_buttons = self.driver.find_elements_by_xpath( '//input[@class="btnBigAddCart"]') sleep(delay) # Add to cart atc_buttons[0].click() # Go to checkout selenium_utils.wait_for_page(self.driver, "EVGA - Checkout") selenium_utils.button_click_using_xpath( self.driver, '//*[@id="LFrame_CheckoutButton"]') # Shipping Address screen selenium_utils.wait_for_page(self.driver, "Shopping") log.info("Skip that page.") self.driver.get("https://secure.evga.com/Cart/Checkout_Payment.aspx") selenium_utils.wait_for_page(self.driver, "EVGA - Checkout - Billing Options") log.info("Ensure that we are paying with credit card") sleep(1) # Fix this. WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable( (By.XPATH, './/input[@value="rdoCreditCard"]'))).click() WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable( (By.XPATH, '//*[@id="ctl00_LFrame_btncontinue"]'))).click() selenium_utils.wait_for_element(self.driver, "ctl00_LFrame_txtNameOnCard") log.info("Populate credit card fields") selenium_utils.field_send_keys(self.driver, "ctl00$LFrame$txtNameOnCard", self.credit_card["name"]) selenium_utils.field_send_keys(self.driver, "ctl00$LFrame$txtCardNumber", self.credit_card["number"]) selenium_utils.field_send_keys(self.driver, "ctl00$LFrame$txtCvv", self.credit_card["cvv"]) Select(self.driver.find_element_by_id( "ctl00_LFrame_ddlMonth")).select_by_value( self.credit_card["expiration_month"]) Select(self.driver.find_element_by_id( "ctl00_LFrame_ddlYear")).select_by_value( self.credit_card["expiration_year"]) WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable(( By.XPATH, "/html/body/form/div[3]/div[3]/div/div[1]/div[5]/div[3]/div/div[1]/div/div[@id='checkoutButtons']/input[2]", ))).click() try: WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable(( By.XPATH, "/html/body/form/div[3]/div[3]/div/div[1]/div[5]/div[3]/div/div[1]/div/div[@id='checkoutButtons']/input[2]", ))).click() except: pass log.info("Finalize Order Page") selenium_utils.wait_for_page(self.driver, "EVGA - Checkout - Finalize Order") WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable( (By.ID, "ctl00_LFrame_cbAgree"))).click() if not test: WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable( (By.ID, "ctl00_LFrame_btncontinue"))).click() log.info("Finalized Order!")
def buy(self, delay=5, test=False): if test: self.driver.get( "https://www.evga.com/products/product.aspx?pn=10G-P5-3897-KR&associatecode=2QME1VF65K9ZY8B" ) selenium_utils.wait_for_page( self.driver, "EVGA - Products - EVGA GeForce RTX 3080 FTW3 ULTRA GAMING, 10G-P5-3897-KR, 10GB GDDR6X, iCX3 Technology, ARGB LED, Metal Backplate - 10G-P5-3897-KR" ) else: self.driver.get( "https://www.evga.com/products/product.aspx?pn=10G-P5-3897-KR&associatecode=2QME1VF65K9ZY8B" ) selenium_utils.wait_for_page( self.driver, "EVGA - Products - EVGA GeForce RTX 3080 FTW3 ULTRA GAMING, 10G-P5-3897-KR, 10GB GDDR6X, iCX3 Technology, ARGB LED, Metal Backplate - 10G-P5-3897-KR", ) #Check for stock log.info("On GPU Page") atc_buttons = self.driver.find_elements_by_xpath( '//input[@class="btnBigAddCart"]') while not atc_buttons: log.info("Refreshing GPU and checking for add to cart button") # self.driver.refresh() self.driver.get( "https://www.evga.com/products/product.aspx?pn=10G-P5-3897-KR&associatecode=2QME1VF65K9ZY8B" ) atc_buttons = self.driver.find_elements_by_xpath( '//input[@class="btnBigAddCart"]') sleep(3) # # Add to cart # atc_buttons[0].click() selenium_utils.button_click_using_xpath( self.driver, '//*[@id="LFrame_btnAddToCart"]') # Go to checkout selenium_utils.wait_for_page(self.driver, "EVGA - Checkout") selenium_utils.button_click_using_xpath( self.driver, '//*[@id="LFrame_CheckoutButton"]') # Shipping Address screen selenium_utils.wait_for_page(self.driver, "Shopping") log.info("Skip that page.") self.driver.get("https://secure.evga.com/Cart/Checkout_Payment.aspx") selenium_utils.wait_for_page(self.driver, "EVGA - Checkout - Billing Options") log.info("Ensure that we are paying with credit card") WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable( (By.XPATH, './/input[@value="rdoCreditCard"]'))).click() WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable( (By.XPATH, '//*[@id="ctl00_LFrame_btncontinue"]'))).click() selenium_utils.wait_for_element(self.driver, "ctl00_LFrame_txtNameOnCard") log.info("Populate credit card fields") selenium_utils.field_send_keys(self.driver, "ctl00$LFrame$txtNameOnCard", self.credit_card["name"]) selenium_utils.field_send_keys(self.driver, "ctl00$LFrame$txtCardNumber", self.credit_card["number"]) selenium_utils.field_send_keys(self.driver, "ctl00$LFrame$txtCvv", self.credit_card["cvv"]) Select(self.driver.find_element_by_id( "ctl00_LFrame_ddlMonth")).select_by_value( self.credit_card["expiration_month"]) Select(self.driver.find_element_by_id( "ctl00_LFrame_ddlYear")).select_by_value( self.credit_card["expiration_year"]) WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable(( By.XPATH, "/html/body/form/div[3]/div[3]/div/div[1]/div[5]/div[3]/div/div[1]/div/div[@id='checkoutButtons']/input[2]", ))).click() log.info("Finalize Order Page") selenium_utils.wait_for_page(self.driver, "EVGA - Checkout - Finalize Order") WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable( (By.ID, "ctl00_LFrame_cbAgree"))).click() selenium_utils.wait_for_element(self.driver, "ctl00_LFrame_btncontinue") if not test: WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable( (By.ID, "ctl00_LFrame_btncontinue"))).click() selenium_utils.wait_for_page(self.driver, "EVGA - Checkout - Order Successful") log.info("Finalized Order!")