Ejemplo n.º 1
0
    def monitor(self, productUrl, worker):
        self.setLogger(
            configureLogger(
                f"Walmart-{getProcessNum(multiprocessing.current_process().name)}"
            ))

        phone = Phone(self.logger)
        phone.startServer(worker.timeToRun)

        headers = {
            "accept":
            "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
            "accept-encoding":
            "gzip, deflate, br",
            "accept-language":
            "en-US,en;q=0.9",
            "cache-control":
            "max-age=0",
            "upgrade-insecure-requests":
            "1",
            "user-agent":
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"
        }

        while not worker.stopEvent.is_set():
            # for i in range(1):
            with requests.Session() as session:
                try:
                    response = session.get(productUrl,
                                           headers=headers,
                                           timeout=60)
                    product = productUrl[27:productUrl[27:].find('/') + 27]
                    if "Add to cart" in response.text:
                        self.logger.info(
                            f"walmart - {product} IN STOCK!!! sending message")
                        with worker.lock:
                            alert()
                            phone.sendMessage(productUrl)
                        doc = lxml.html.fromstring(response.text)
                        offerId = json.loads(
                            doc.xpath('//script[@id="item"]/text()')
                            [0])["item"]["product"]["buyBox"]["products"][0][
                                "offerId"]
                        # self.atc(productUrl, offerId)
                        # self.checkout(worker.stopEvent)
                    # else:
                    #     self.logger.info(f"walmart - Out of stock for {product}!")
                except:
                    self.logger.exception("ERROR: could not send request!",
                                          exc_info=True)
                time.sleep(worker.checkTime.value)
        phone.close()
Ejemplo n.º 2
0
    def monitor(self, productUrl, worker):
        self.setLogger(
            configureLogger(
                f"Gamestop-{getProcessNum(multiprocessing.current_process().name)}"
            ))

        phone = Phone(self.logger)
        phone.startServer(worker.timeToRun)

        headers = {
            "accept":
            "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
            "accept-encoding":
            "gzip, deflate, br",
            "accept-language":
            "en-US,en;q=0.9",
            "cache-control":
            "max-age=0",
            "Referer":
            "https://www.gamestop.com/video-games/switch",
            "upgrade-insecure-requests":
            "1",
            "user-agent":
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"
        }

        while not worker.stopEvent.is_set():
            # for i in range(1):
            with requests.Session() as session:
                try:
                    response = session.get(productUrl,
                                           headers=headers,
                                           timeout=60)
                    product = productUrl[62:productUrl[62:].find('/') + 62]
                    if not "Not Available" in response.text:
                        self.logger.info(
                            f"Gamestop - {product} IN STOCK!!! sending message"
                        )
                        with worker.lock:
                            alert()
                            phone.sendMessage(productUrl)
                        # self.atc(productUrl)
                        # self.checkout(worker.stopEvent)
                    # else:
                    #     self.logger.info(f"Gamestop - Out of stock for {product}!")
                except:
                    self.logger.exception("ERROR: could not send request!",
                                          exc_info=True)
                time.sleep(worker.checkTime.value)
Ejemplo n.º 3
0
    def monitor(self, productUrl, worker, apiLock):
        processNum = getProcessNum(multiprocessing.current_process().name)
        self.setLogger(configureLogger(f"BestBuy-{processNum}"))

        phone = Phone(self.logger)
        phone.startServer(worker.timeToRun)

        sku = productUrl[productUrl.find('skuId=') +
                         6:productUrl.find('skuId=') + 6 + 7]
        url = f"https://api.bestbuy.com/v1/products/{sku}.json?apiKey={self.key}"

        while not worker.stopEvent.is_set():
            # for i in range(1):
            with requests.Session() as session:
                try:
                    with apiLock:
                        response = session.get(url, timeout=60)
                        time.sleep(0.5)
                    value = json.loads(response.text)
                    # self.printResults(value)

                    if value['onlineAvailability']:
                        self.logger.info(
                            f"best buy - {value['name']} IN STOCK!!! sending message"
                        )
                        with worker.lock:
                            alert()
                            phone.sendMessage(productUrl)
                        # self.atc(productUrl, sku)
                        # self.checkout(worker.stopEvent)
                    # else:
                    #     self.logger.info(f"best buy - Out of stock for {value['name']}")
                except:
                    self.logger.exception("ERROR: could not send request!",
                                          exc_info=True)
                time.sleep(worker.checkTime.value)
        phone.close()
Ejemplo n.º 4
0
    # worker.phone.close()
    sys.exit(1)


if __name__ == '__main__':
    configFile = os.path.join(os.getcwd(), "config.json")
    with open(configFile) as f:
        data = json.load(f)

    jobs = []
    lock = multiprocessing.Lock()
    checkTime = multiprocessing.Value('i', data['checkTime'])
    stopEvent = multiprocessing.Event()
    timeToRun = data['timeToRun']
    logger = configureLogger('main')

    worker = Worker(checkTime, stopEvent, lock, timeToRun)
    bestBuyBot = BestBuy()
    walmartBot = Walmart()
    targetBot = Target()
    gamestopBot = Gamestop()
    kohlsBot = Kohls()
    costcoBot = Costco()
    samsclubBot = SamsClub()

    # test(worker, bestBuyBot, walmartBot, targetBot, gamestopBot, kohlsBot, costcoBot, samsclubBot)

    createBestBuyProcesses(data['bestbuy'], jobs, logger, bestBuyBot)
    createWalmartProcesses(data['walmart'], jobs, logger, walmartBot)
    createTargetProcesses(data['target'], jobs, logger, targetBot)