Skip to content

Commit

Permalink
添加预约抢购一体化,自动获取预约和抢购时间
Browse files Browse the repository at this point in the history
  • Loading branch information
yilei committed Mar 4, 2020
1 parent 4bffde8 commit 7c0e9c6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
15 changes: 15 additions & 0 deletions jd_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,21 @@ def _get_reserve_url(self, sku_id):
reserve_url = resp_json.get('url')
return 'https:' + reserve_url if reserve_url else None

def get_reserve_info(self, sku_id):
url = 'https://yushou.jd.com/youshouinfo.action'
payload = {
'callback': 'fetchJSON',
'sku': sku_id,
}
headers = {
'User-Agent': self.user_agent,
'Referer': 'https://item.jd.com/{}.html'.format(sku_id),
}
resp = self.sess.get(url=url, params=payload, headers=headers)
resp_json = parse_json(resp.text)
# {"type":"1","hasAddress":false,"riskCheck":"0","flag":false,"num":941723,"stime":"2018-10-12 12:40:00","plusEtime":"","qiangEtime":"","showPromoPrice":"0","qiangStime":"","state":2,"sku":100000287121,"info":"\u9884\u7ea6\u8fdb\u884c\u4e2d","isJ":0,"address":"","d":48824,"hidePrice":"0","yueEtime":"2018-10-19 15:01:00","plusStime":"","isBefore":0,"url":"//yushou.jd.com/toYuyue.action?sku=100000287121&key=237af0174f1cffffd227a2f98481a338","etime":"2018-10-19 15:01:00","plusD":48824,"category":"4","plusType":0,"yueStime":"2018-10-12 12:40:00"};
return resp_json

@check_login
def make_reserve(self, sku_id, buy_time):
"""商品预约
Expand Down
42 changes: 42 additions & 0 deletions mainV2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from jd_assistant import Assistant
import random

if __name__ == '__main__':
"""
重要提示:此处为示例代码之一,请移步下面的链接查看使用教程👇
https://github.com/tychxn/jd-assistant/wiki/1.-%E4%BA%AC%E4%B8%9C%E6%8A%A2%E8%B4%AD%E5%8A%A9%E6%89%8B%E7%94%A8%E6%B3%95
"""
#area = '19_1607_4773' # 区域id
asst = Assistant() # 初始化
asst.login_by_QRcode() # 扫码登陆
# 获取参数信息
model_type = input("请输入购买类型(1.定时预约抢购 2.正常有货购买 3.正常定时购买):")
if model_type == '1':
print("定时预约抢购...")
sku_id = input("请输入一个sku_id:")
reserve_info = asst.get_reserve_info(sku_id)
reserve_time = reserve_info.get("yueStime")
buy_time = reserve_info.get("qiangStime")
print("预约时间:",reserve_time)
print("抢购时间:",buy_time)
# 开始预约
asst.make_reserve(sku_id, reserve_time + '.000')
# 开始抢购
rand_msecond = random.randint(1,9) * 1000
buy_time = buy_time + "." + str(rand_msecond)
#asst.exec_reserve_seckill_by_time(sku_id=sku_id,buy_time=time, retry=10, interval=1,num=1)
asst.exec_seckill_by_time(sku_ids=sku_id,buy_time=buy_time, retry=10, interval=1,num=1)
elif model_type == '2':
print("正常有货购买...")
sku_ids = input("请输入一个或多个sku_id:")
area = input("请输入area_id:")
asst.buy_item_in_stock(sku_ids=sku_ids, area=area, wait_all=False, stock_interval=5)
elif model_type == '3':
print("正常定时购买...")
sku_ids = input("请输入一个或多个sku_id:")
buy_time = input("请输入定时购买时间(2020-03-04 00:59:59.000):")
asst.clear_cart() # 清空购物车(可选)
asst.add_item_to_cart(sku_ids=sku_ids) # 根据商品id添加购物车(可选)
asst.submit_order_by_time(buy_time=buy_time, retry=10, interval=5) # 定时提交订单

0 comments on commit 7c0e9c6

Please sign in to comment.