예제 #1
0
파일: evga.py 프로젝트: jrwhetse/nvidia-bot
    def login(self, username, password):
        """
        We're just going to enter the user info and let the user handle the captcha
        :param username:
        :param password:
        :return:
        """
        self.driver.execute_cdp_cmd(
            "Network.setUserAgentOverride",
            {
                "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.53 Safari/537.36"
            },
        )
        self.driver.execute_script(
            "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
        )

        self.driver.get(LOGIN_URL)
        selenium_utils.wait_for_page(self.driver, "EVGA - Intelligent Innovation")

        selenium_utils.field_send_keys(self.driver, "evga_login", username)
        selenium_utils.field_send_keys(self.driver, "password", password)

        log.info("Go do the captcha and log in")

        selenium_utils.wait_for_page(
            self.driver, "EVGA - Intelligent Innovation - Official Website", 300
        )
        log.info("Logged in!")
예제 #2
0
    def sign_in(self):
        log.info("Signing in.")
        self.driver.get(
            f"https://store.nvidia.com/DRHM/store?Action=Logout&SiteID=nvidia&Locale={self.locale}&ThemeID=326200&Env=BASE&nextAction=help"
        )
        selenium_utils.wait_for_page(
            self.driver, PAGE_TITLES_BY_LOCALE[self.locale]["signed_in_help"])

        if not self.is_signed_in():
            email = selenium_utils.wait_for_element(self.driver, "loginEmail")
            pwd = selenium_utils.wait_for_element(self.driver, "loginPassword")
            try:
                email.send_keys(self.nvidia_login)
                pwd.send_keys(self.nvidia_password)
            except AttributeError as e:
                log.error("Missing 'nvidia_login' or 'nvidia_password'")
                raise e
            try:
                action = ActionChains(self.driver)
                button = self.driver.find_element_by_xpath(
                    '//*[@id="dr_siteButtons"]/input')

                action.move_to_element(button).click().perform()
                WebDriverWait(self.driver, 5).until(ec.staleness_of(button))
            except NoSuchElementException:
                log.error("Error signing in.")
예제 #3
0
 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?")
예제 #4
0
    def selenium_checkout(self):
        log.info("Checking out.")
        autobuy_btns = autobuy_locale_btns[self.locale]
        params = {"token": self.access_token}
        url = furl(DIGITAL_RIVER_CHECKOUT_URL).set(params)
        self.driver.get(url.url)
        log.debug(
            f"Waiting for page title: {PAGE_TITLES_BY_LOCALE[self.locale]['checkout']}"
        )
        selenium_utils.wait_for_page(
            self.driver, PAGE_TITLES_BY_LOCALE[self.locale]["checkout"])

        log.info("Next.")
        log.debug(f"Clicking on button: {autobuy_btns[0]}")
        self.driver.find_element_by_xpath(
            f'//*[@value="{autobuy_btns[0]}"]').click()
        log.debug(f"Entering security code to 'cardSecurityCode'")
        security_code = selenium_utils.wait_for_element(
            self.driver, "cardSecurityCode")
        security_code.send_keys(self.cvv)
        log.info("Next.")
        log.debug(f"Clicking on button: {autobuy_btns[0]}")
        self.driver.find_element_by_xpath(
            f'//*[@value="{autobuy_btns[0]}"]').click()

        try:
            log.debug(
                f"Waiting for page title: {PAGE_TITLES_BY_LOCALE[self.locale]['verify_order']}"
            )
            selenium_utils.wait_for_page(
                self.driver,
                PAGE_TITLES_BY_LOCALE[self.locale]["verify_order"], 5)
        except TimeoutException:
            log.debug("Address validation required?")
            self.address_validation_page()

        log.debug(
            f"Waiting for page title: {PAGE_TITLES_BY_LOCALE[self.locale]['verify_order']}"
        )
        selenium_utils.wait_for_page(
            self.driver, PAGE_TITLES_BY_LOCALE[self.locale]["verify_order"], 5)
        log.info("Submit.")
        log.debug("Reached order validation page.")
        self.driver.save_screenshot("nvidia-order-validation.png")
        self.driver.find_element_by_xpath(
            f'//*[@value="{autobuy_btns[1]}"]').click()
        selenium_utils.wait_for_page(
            self.driver, PAGE_TITLES_BY_LOCALE[self.locale]["order_completed"],
            5)
        self.driver.save_screenshot("nvidia-order-finshed.png")
        log.info("Done.")
예제 #5
0
    def login(self, username, password):
        """
        We're just going to attempt to load cookies, else enter the user info and let the user handle the captcha
        :param username:
        :param password:
        :return:
        """
        self.driver.execute_cdp_cmd(
            "Network.setUserAgentOverride",
            {
                "userAgent":
                "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.53 Safari/537.36"
            },
        )
        self.driver.execute_script(
            "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
        )

        if path.isfile("evga-cookies.pkl"):  # check for cookies file
            self.driver.get("https://www.evga.com")
            selenium_utils.wait_for_page(
                self.driver,
                "EVGA - Intelligent Innovation - Official Website", 300)
            cookies = pickle.load(open("evga-cookies.pkl", "rb"))
            for cookie in cookies:
                self.driver.add_cookie(cookie)

        self.driver.get("https://www.evga.com")
        selenium_utils.wait_for_page(
            self.driver, "EVGA - Intelligent Innovation - Official Website",
            300)
        if (len(self.driver.find_elements_by_id("svg-login")) >
                0):  # cookies did not provide logged in state
            self.driver.get(LOGIN_URL)
            selenium_utils.wait_for_page(self.driver,
                                         "EVGA - Intelligent Innovation")

            selenium_utils.field_send_keys(self.driver, "evga_login", username)
            selenium_utils.field_send_keys(self.driver, "password", password)

            log.info("Go do the captcha and log in")

            selenium_utils.wait_for_page(
                self.driver,
                "EVGA - Intelligent Innovation - Official Website", 300)
            pickle.dump(self.driver.get_cookies(),
                        open("evga-cookies.pkl", "wb"))  # save cookies

        log.info("Logged in!")
예제 #6
0
    def selenium_checkout(self):
        log.info("Checking out.")
        autobuy_btns = autobuy_locale_btns[self.locale]
        params = {"token": self.access_token}
        url = furl(DIGITAL_RIVER_CHECKOUT_URL).set(params)
        self.driver.get(url.url)
        log.debug(
            f"Waiting for page title: {PAGE_TITLES_BY_LOCALE[self.locale]['checkout']}"
        )
        selenium_utils.wait_for_page(
            self.driver, PAGE_TITLES_BY_LOCALE[self.locale]["checkout"])

        log.info("Next.")
        log.debug(f"Clicking on button: {autobuy_btns[0]}")
        self.driver.find_element_by_xpath(
            f'//*[@value="{autobuy_btns[0]}"]').click()
        log.debug(f"Entering security code to 'cardSecurityCode'")
        security_code = selenium_utils.wait_for_element(
            self.driver, "cardSecurityCode")
        security_code.send_keys(self.cvv)
        log.info("Next.")
        log.debug(f"Clicking on button: {autobuy_btns[0]}")
        self.driver.find_element_by_xpath(
            f'//*[@value="{autobuy_btns[0]}"]').click()

        try:
            log.debug(
                f"Waiting for page title: {PAGE_TITLES_BY_LOCALE[self.locale]['verify_order']}"
            )
            selenium_utils.wait_for_page(
                self.driver,
                PAGE_TITLES_BY_LOCALE[self.locale]["verify_order"], 5)
        except TimeoutException:
            log.debug("Address validation required?")
            self.address_validation_page()

        log.debug(
            f"Waiting for page title: {PAGE_TITLES_BY_LOCALE[self.locale]['verify_order']}"
        )
        selenium_utils.wait_for_page(
            self.driver, PAGE_TITLES_BY_LOCALE[self.locale]["verify_order"], 5)

        if not self.test:
            log.info("F this captcha lmao. Submitting cart.")
            self.submit_cart()
        else:
            log.info("Test complete. No actual purchase was made.")
예제 #7
0
    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!")
예제 #8
0
    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!")
예제 #9
0
    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!")