Browse Source

<feat>(waitAndBuy):Out of stock on the shelf automatic timing order (common goods, non-seckill buying)

master
Louis Young 3 years ago
parent
commit
cd57563d11
  1. 7
      .idea/workspace.xml
  2. 43
      WaitingAndBuy.py
  3. 12
      main.py

7
.idea/workspace.xml

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="557626c8-a0b7-4bf6-b000-aaaff199c3dd" name="默认更改列表" comment="" />
<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" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -67,7 +69,8 @@ @@ -67,7 +69,8 @@
<option name="presentableId" value="Default" />
<updated>1625960643880</updated>
<workItem from="1625960646818" duration="5632000" />
<workItem from="1625970377756" duration="4993000" />
<workItem from="1625970377756" duration="5103000" />
<workItem from="1626100177418" duration="1278000" />
</task>
<servers />
</component>

43
WaitingAndBuy.py

@ -1,12 +1,11 @@ @@ -1,12 +1,11 @@
import math
import functools
import sys
from lxml import html
import requests
import time
import json
import random
import sys
from concurrent.futures import ProcessPoolExecutor
from exception import SKException
from bs4 import BeautifulSoup
@ -14,6 +13,7 @@ from config import global_config @@ -14,6 +13,7 @@ from config import global_config
from logger import logger
from login import SpiderSession, QrLogin
from message import sendMessage
from timer import Timer
from util import parse_json
@ -32,6 +32,7 @@ class Waiter(): @@ -32,6 +32,7 @@ class Waiter():
self.item_vender_ids = dict() # 记录商家id
self.timeout = float(global_config.getRaw('config', 'timeout'))
self.headers = {'User-Agent': self.user_agent}
self.timers = Timer()
def login_by_qrcode(self):
"""
@ -65,6 +66,9 @@ class Waiter(): @@ -65,6 +66,9 @@ class Waiter():
def waitForSell(self):
self._waitForSell()
def waitTimeForSell(self):
self._waitTimeForSell()
def get_tag_value(self, tag, key='', index=0):
if key:
value = tag[index].get(key)
@ -153,6 +157,12 @@ class Waiter(): @@ -153,6 +157,12 @@ class Waiter():
else:
time.sleep(random.randint(1, 10))
def _waitTimeForSell(self):
self.initCart()
logger.info("正在等待商品上架:{}".format(self.get_sku_title()[:40] + " ......"))
self.timers.start()
self.fastBuy()
def get_single_item_stock(self):
"""获取单个商品库存状态
@ -467,7 +477,7 @@ class Waiter(): @@ -467,7 +477,7 @@ class Waiter():
logger.error('订单结算页面获取异常:%s' % e)
except Exception as e:
logger.error('下单页面数据解析异常:%s', e)
return risk_control
return -1
def submit_order(self, risk_control):
@ -540,7 +550,8 @@ class Waiter(): @@ -540,7 +550,8 @@ class Waiter():
if resp_json.get('success'):
logger.info('订单提交成功! 订单号:%s', resp_json.get('orderId'))
sendMessage('订单提交成功! 订单号:{}'.format(resp_json.get('orderId')))
sys.exit(0)
sys.exit(1)
return True
else:
message, result_code = resp_json.get('message'), resp_json.get('resultCode')
if result_code == 0:
@ -697,3 +708,27 @@ class Waiter(): @@ -697,3 +708,27 @@ class Waiter():
logger.info('执行结束,提交订单失败!')
return False
@check_login
def initCart(self):
sku_id = global_config.getRaw('config', 'sku_id')
self.add_item_to_cart(sku_id)
self.cancel_select_all_cart_item()
@check_login
def fastBuy(self):
retry = eval(global_config.getRaw("config", "retry"))
for count in range(retry):
logger.info('第[%s/%s]次尝试提交订单', count, retry)
risk_control = self.get_checkout_page_detail()
if risk_control == -1:
continue
if risk_control == '刷新太频繁了':
return False
if len(risk_control) > 0:
if self.submit_order(risk_control):
return True
logger.info('休息%ss', 3)
time.sleep(3)
else:
logger.info('执行结束,提交订单失败!')
return False

12
main.py

@ -6,18 +6,19 @@ from WaitingAndBuy import Waiter @@ -6,18 +6,19 @@ from WaitingAndBuy import Waiter
if __name__ == '__main__':
choiceList = """
===== 注意 =====
使用前请按要求填写config.ini中的
使用前请按要求填写config.ini中的信息
功能列表
1.预约商品
2.秒杀抢购商品
3.缺货上架自动加购物车下单
3.自动加购物车缺货等待上架自动下单
4.缺货上架自动定时下单普通商品非秒杀抢购
"""
print(choiceList)
choice_function = global_config.getRaw("config", "mode")
if choice_function == '':
choice_function = input('请选择:')
global_config.setMode(choice_function)
global_config.setModel(choice_function)
if choice_function == '1':
jd_seckill = Seckiller()
jd_seckill.reserve()
@ -27,6 +28,9 @@ if __name__ == '__main__': @@ -27,6 +28,9 @@ if __name__ == '__main__':
elif choice_function == '3':
waiter = Waiter()
waiter.waitForSell()
elif choice_function == '4':
waiter = Waiter()
waiter.waitTimeForSell()
else:
print('没有此功能')
sys.exit(1)

Loading…
Cancel
Save