Ejemplo n.º 1
0
 def in_stock(self):
     log.info("Checking stock")
     url = "https://www.bestbuy.com/api/tcfb/model.json?paths=%5B%5B%22shop%22%2C%22scds%22%2C%22v2%22%2C%22page%22%2C%22tenants%22%2C%22bbypres%22%2C%22pages%22%2C%22globalnavigationv5sv%22%2C%22header%22%5D%2C%5B%22shop%22%2C%22buttonstate%22%2C%22v5%22%2C%22item%22%2C%22skus%22%2C{}%2C%22conditions%22%2C%22NONE%22%2C%22destinationZipCode%22%2C%22%2520%22%2C%22storeId%22%2C%22%2520%22%2C%22context%22%2C%22cyp%22%2C%22addAll%22%2C%22false%22%5D%5D&method=get".format(
         self.sku_id)
     response = self.session.get(url, headers=DEFAULT_HEADERS)
     log.info(f"Stock check response code: {response.status_code}")
     try:
         response_json = response.json()
         item_json = find_values(json.dumps(response_json),
                                 "buttonStateResponseInfos")
         item_state = item_json[0][0]["buttonState"]
         log.info(f"Item state is: {item_state}")
         if item_json[0][0][
                 "skuId"] == self.sku_id and item_state == "ADD_TO_CART":
             return True
         else:
             return False
     except Exception as e:
         log.warning(
             "Error parsing json. Using string search to determine state.")
         log.info(response_json)
         log.error(e)
         if "ADD_TO_CART" in response.text:
             log.info("Item is in stock!")
             return True
         else:
             log.info("Item is out of stock")
             return False
Ejemplo n.º 2
0
 def in_stock(self):
     self.status_signal.emit(create_msg("Checking stock", "normal"))
     url = "https://www.bestbuy.com/api/tcfb/model.json?paths=%5B%5B%22shop%22%2C%22scds%22%2C%22v2%22%2C%22page%22%2C%22tenants%22%2C%22bbypres%22%2C%22pages%22%2C%22globalnavigationv5sv%22%2C%22header%22%5D%2C%5B%22shop%22%2C%22buttonstate%22%2C%22v5%22%2C%22item%22%2C%22skus%22%2C{}%2C%22conditions%22%2C%22NONE%22%2C%22destinationZipCode%22%2C%22%2520%22%2C%22storeId%22%2C%22%2520%22%2C%22context%22%2C%22cyp%22%2C%22addAll%22%2C%22false%22%5D%5D&method=get".format(
         self.sku_id
     )
     # TODO: Add random delay configuration
     response = self.session.get(url, headers=DEFAULT_HEADERS)
     self.status_signal.emit(create_msg(f"Stock check response code: {response.status_code}", "normal"))
     try:
         response_json = response.json()
         item_json = find_values(
             json.dumps(response_json), "buttonStateResponseInfos"
         )
         item_state = item_json[0][0]["buttonState"]
         self.status_signal.emit(create_msg(f"Item state is: {item_state}", "normal"))
         if item_json[0][0]["skuId"] == self.sku_id and item_state in [
             "ADD_TO_CART",
             "PRE_ORDER"
         ]:
             return True
         else:
             return False
     except Exception as e:
         self.status_signal.emit(create_msg("Error parsing json. Using string search to determine state.", "error"))
         self.status_signal.emit(create_msg(f"{response_json}", "normal"))
         self.status_signal.emit(create_msg(f"{e}", "error"))
         if "ADD_TO_CART" in response.text: #TODO: Make this case insensitive
             self.status_signal.emit(create_msg("Item is in stock!", "normal"))
             return True
         else:
             self.status_signal.emit(create_msg("Item is out of stock", "normal"))
             webdriver.refresh()
             return False