def checkout_selenium(driver, timeout, promo_locale, target_gpu, notifications,
                      notification_queue):
    logging.info(
        f"Checking {promo_locale} availability for {target_gpu['name']} using selenium..."
    )
    product_loaded = nvidia.get_product_page(driver, promo_locale, target_gpu)
    if product_loaded:
        gpu_available = nvidia.check_availability(driver, timeout)
        if gpu_available:
            logging.info(f"Found available GPU: {target_gpu['name']}")
            if notifications['availability']['enabled']:
                driver.save_screenshot(const.SCREENSHOT_FILE)
                notification_queue.put('availability')
            added_to_basket = False
            while not added_to_basket:
                logging.info(f'Trying to add to basket...')
                added_to_basket = nvidia.add_to_basket(driver, timeout)
                if not added_to_basket:
                    logging.info(f'Add to basket click failed, trying again!')
            logging.info(f'Add to basket click suceeded!')
            if notifications['add-to-basket']['enabled']:
                driver.save_screenshot(const.SCREENSHOT_FILE)
                notification_queue.put('add-to-basket')
            logging.info('Going to checkout page...')
            checkout_reached = nvidia.to_checkout(driver, timeout,
                                                  promo_locale,
                                                  notification_queue)
            if checkout_reached:
                return True
            else:
                logging.error(
                    'Lost basket and failed to checkout, trying again...')
                return False
        else:
            logging.info('GPU currently not available')
        return False
    else:
        return False
Esempio n. 2
0
    while True:
        logging.info(
            f"Checking {locale} availability for {target_gpu['name']}...")
        nvidia.get_product_page(driver, locale, target_gpu)

        gpu_available = nvidia.check_availability(driver, timeout)
        if gpu_available:
            logging.info(f"Found available GPU: {target_gpu['name']}")
            if notification_config['availability']['enabled']:
                driver.save_screenshot(const.SCREENSHOT_FILE)
                notification_queue.put('availability')

            added_to_basket = False
            while not added_to_basket:
                logging.info(f'Trying to add to basket...')
                added_to_basket = nvidia.add_to_basket(driver, timeout)
                if not added_to_basket:
                    logging.info(f'Add to basket click failed, trying again!')

            logging.info(f'Add to basket click suceeded!')
            if notification_config['add-to-basket']['enabled']:
                driver.save_screenshot(const.SCREENSHOT_FILE)
                notification_queue.put('add-to-basket')

            logging.info('Going to checkout page...')
            checkout_reached = nvidia.to_checkout(
                driver, timeout, locale, notification_queue)
            if checkout_reached:
                if payment_method == 'credit-card':
                    nvidia.checkout_guest(
                        driver, timeout, customer, auto_submit)