Esempio n. 1
0
    def __init__(self, gpu, locale="en_us", test=False, interval=5):
        self.product_ids = set([])
        self.cli_locale = locale.lower()
        self.locale = self.map_locales()
        self.session = requests.Session()
        self.gpu = gpu
        self.enabled = True
        self.auto_buy_enabled = False
        self.attempt = 0
        self.started_at = datetime.now()
        self.test = test
        self.interval = interval

        self.gpu_long_name = GPU_DISPLAY_NAMES[gpu]

        # Disable auto_buy_enabled if the user does not provide a bool.
        if type(self.auto_buy_enabled) != bool:
            self.auto_buy_enabled = False

        adapter = TimeoutHTTPAdapter(max_retries=Retry(
            total=10,
            backoff_factor=1,
            status_forcelist=[429, 500, 502, 503, 504],
            method_whitelist=["HEAD", "GET", "OPTIONS"],
        ))
        self.session.mount("https://", adapter)
        self.session.mount("http://", adapter)
        self.notification_handler = NotificationHandler()

        self.get_product_ids()
        print(self.product_ids)
Esempio n. 2
0
    def __init__(self,
                 gpu,
                 notification_handler,
                 locale="en_us",
                 test=False,
                 interval=5):
        self.product_ids = set([])
        self.cli_locale = locale.lower()
        self.locale = self.map_locales()
        self.session = requests.Session()
        self.gpu = gpu
        self.enabled = True
        self.auto_buy_enabled = False
        self.attempt = 0
        self.started_at = datetime.now()
        self.test = test
        self.interval = interval

        self.gpu_long_name = GPU_DISPLAY_NAMES[gpu]

        self.cj = browser_cookie3.load(".nvidia.com")
        self.session.cookies = self.cj

        # Disable auto_buy_enabled if the user does not provide a bool.
        if type(self.auto_buy_enabled) != bool:
            self.auto_buy_enabled = False

        adapter = TimeoutHTTPAdapter()
        self.session.mount("https://", adapter)
        self.session.mount("http://", adapter)
        self.notification_handler = notification_handler

        self.get_product_ids()
Esempio n. 3
0
    def __init__(self, gpu, locale="en_us", test=False):
        self.product_ids = set([])
        self.cli_locale = locale.lower()
        self.locale = self.map_locales()
        self.session = requests.Session()
        self.gpu = gpu
        self.enabled = True
        self.auto_buy_enabled = False
        self.attempt = 0
        self.started_at = datetime.now()
        self.test = test

        self.gpu_long_name = GPU_DISPLAY_NAMES[gpu]

        if path.exists(AUTOBUY_CONFIG_PATH):
            with open(AUTOBUY_CONFIG_PATH) as json_file:
                try:
                    self.config = json.load(json_file)
                except Exception as e:
                    log.error(
                        "Your `autobuy_config.json` file is not valid json.")
                    raise e
                if self.has_valid_creds():
                    self.nvidia_login = self.config["NVIDIA_LOGIN"]
                    self.nvidia_password = self.config["NVIDIA_PASSWORD"]
                    self.auto_buy_enabled = self.config["FULL_AUTOBUY"]
                    self.cvv = self.config.get("CVV")
                    self.interval = int(self.config.get("INTERVAL", 5))
                else:
                    raise InvalidAutoBuyConfigException(self.config)
        else:
            log.info("No Autobuy creds found.")

        # Disable auto_buy_enabled if the user does not provide a bool.
        if type(self.auto_buy_enabled) != bool:
            self.auto_buy_enabled = False

        adapter = TimeoutHTTPAdapter(max_retries=Retry(
            total=10,
            backoff_factor=1,
            status_forcelist=[429, 500, 502, 503, 504],
            method_whitelist=["HEAD", "GET", "OPTIONS"],
        ))
        self.session.mount("https://", adapter)
        self.session.mount("http://", adapter)
        self.notification_handler = NotificationHandler()

        log.info("Opening Webdriver")
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_experimental_option("excludeSwitches",
                                               ["enable-logging"])
        self.driver = webdriver.Chrome(executable_path=binary_path,
                                       options=options,
                                       chrome_options=chrome_options)
        self.sign_in()
        selenium_utils.add_cookies_to_session_from_driver(
            self.driver, self.session)
        log.info("Adding driver cookies to session")

        log.info("Getting product IDs")
        self.token_data = self.get_nvidia_access_token()
        self.payment_option = self.get_payment_options()
        if not self.payment_option.get("id") or not self.cvv:
            log.error(
                "No payment option on account or missing CVV. Disable Autobuy")
            self.auto_buy_enabled = False
        else:
            log.debug(self.payment_option)
            self.ext_ip = self.get_ext_ip()

        if not self.auto_buy_enabled:
            log.info("Closing webdriver")
            self.driver.close()

        self.get_product_ids()
        while len(self.product_ids) == 0:
            log.info(
                f"We have no product IDs for {self.gpu_long_name}, retrying until we get a product ID"
            )
            self.get_product_ids()
            sleep(5)