From 7c0e9c6c5ee5c0a0acb40ca570ca2edca03cde0a Mon Sep 17 00:00:00 2001 From: yilei <87119538@qq.com> Date: Wed, 4 Mar 2020 17:33:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A2=84=E7=BA=A6=E6=8A=A2?= =?UTF-8?q?=E8=B4=AD=E4=B8=80=E4=BD=93=E5=8C=96=EF=BC=8C=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=A2=84=E7=BA=A6=E5=92=8C=E6=8A=A2=E8=B4=AD?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jd_assistant.py | 15 +++++++++++++++ mainV2.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 mainV2.py diff --git a/jd_assistant.py b/jd_assistant.py index ca8e1f4..46431c8 100644 --- a/jd_assistant.py +++ b/jd_assistant.py @@ -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): """商品预约 diff --git a/mainV2.py b/mainV2.py new file mode 100644 index 0000000..5af2f88 --- /dev/null +++ b/mainV2.py @@ -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) # 定时提交订单