Browse Source

<perf>(waiter): add good to cart first

master
Louis Young 3 years ago
parent
commit
3ce10cf9d6
  1. 118
      .gitignore
  2. 7
      .idea/workspace.xml
  3. 22
      WaitingAndBuy.py

118
.gitignore vendored

@ -0,0 +1,118 @@ @@ -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/

7
.idea/workspace.xml

@ -1,11 +1,7 @@ @@ -1,11 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="557626c8-a0b7-4bf6-b000-aaaff199c3dd" name="默认更改列表" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/WaitingAndBuy.py" beforeDir="false" afterPath="$PROJECT_DIR$/WaitingAndBuy.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
</list>
<list default="true" id="557626c8-a0b7-4bf6-b000-aaaff199c3dd" name="默认更改列表" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -74,6 +70,7 @@ @@ -74,6 +70,7 @@
<workItem from="1625970377756" duration="5103000" />
<workItem from="1626100177418" duration="1278000" />
<workItem from="1626104617311" duration="879000" />
<workItem from="1626141965999" duration="205000" />
</task>
<servers />
</component>

22
WaitingAndBuy.py

@ -147,11 +147,13 @@ class Waiter(): @@ -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(): @@ -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(): @@ -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(): @@ -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:

Loading…
Cancel
Save