From 3ce10cf9d67a1627ffd18dd7debf359e8eb8f867 Mon Sep 17 00:00:00 2001 From: Louis Young <1462648167> Date: Tue, 13 Jul 2021 18:47:55 +0800 Subject: [PATCH] (waiter): add good to cart first --- .gitignore | 118 ++++++++++++++++++++++++++++++++++++++++++++ .idea/workspace.xml | 7 +-- WaitingAndBuy.py | 24 ++++----- 3 files changed, 132 insertions(+), 17 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8db915b --- /dev/null +++ b/.gitignore @@ -0,0 +1,118 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# PyCharm +.idea/ diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d35f329..39b2fa7 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,11 +1,7 @@ - - - - - + diff --git a/WaitingAndBuy.py b/WaitingAndBuy.py index 0c8d203..7572fb6 100644 --- a/WaitingAndBuy.py +++ b/WaitingAndBuy.py @@ -147,11 +147,13 @@ class Waiter(): return page def _waitForSell(self): - logger.info("正在等待商品上架:{}".format(self.get_sku_title()[:40] + " ......")) + area_id = self.area + sku_id = self.skuids + logger.info("正在等待商品上架:{}".format(self.get_sku_title()[:80] + " ......")) while True: - if self.get_single_item_stock(): - sendMessage("商品上架: {}".format(self.get_sku_title()[:40] + " ......")) - logger.info("商品上架: {}".format(self.get_sku_title()[:40] + " ......")) + if self.get_single_item_stock(sku_id, area_id): + sendMessage("商品上架: {}".format(self.get_sku_title()[:80] + " ......")) + logger.info("商品上架: {}".format(self.get_sku_title()[:80] + " ......")) # self.waitAndBuy_by_proc_pool() self.buy() else: @@ -159,20 +161,18 @@ class Waiter(): def _waitTimeForSell(self): self.initCart() - logger.info("正在等待商品上架:{}".format(self.get_sku_title()[:40] + " ......")) + logger.info("正在等待商品上架:{}".format(self.get_sku_title()[:80] + " ......")) self.timers.start() self.fastBuy() - def get_single_item_stock(self): + def get_single_item_stock(self, sku_id, area_id): """获取单个商品库存状态 :param sku_id: 商品id :param num: 商品数量 :param area: 地区id :return: 商品是否有货 True/False """ - area_id = self.area - sku_id = self.skuids url = 'https://cd.jd.com/stocks' # https://cd.jd.com/stocks?callback=jQuery3528455&type=getstocks&skuIds=100011513445&area=21_1827_4101_40925&_=1625970219360 payload = { @@ -234,7 +234,7 @@ class Waiter(): # chrome_options.add_argument('blink-settings=imagesEnabled=false') # chrome_options.add_argument('--disable-gpu') # - # logger.info("正在等待商品上架:{}".format(self.get_sku_title()[:40] + " ......")) + # logger.info("正在等待商品上架:{}".format(self.get_sku_title()[:80] + " ......")) # driver = webdriver.Chrome('/usr/local/bin/chromedriver', options=chrome_options) # driver.maximize_window() # @@ -254,8 +254,8 @@ class Waiter(): # state = True # if state: # driver.quit() - # sendMessage("商品上架: {}".format(self.get_sku_title()[:40] + " ......")) - # logger.info("商品上架: {}".format(self.get_sku_title()[:40] + " ......")) + # sendMessage("商品上架: {}".format(self.get_sku_title()[:80] + " ......")) + # logger.info("商品上架: {}".format(self.get_sku_title()[:80] + " ......")) # # self.waitAndBuy_by_proc_pool() # self.buy() # else: @@ -745,4 +745,4 @@ class Waiter(): time.sleep(3) else: logger.info('执行结束,提交订单失败!') - return False + return False \ No newline at end of file