def submit_seckill_order(self): """提交抢购(秒杀)订单 :return: 抢购结果 True/False """ url = 'https://marathon.jd.com/seckillnew/orderService/pc/submitOrder.action' payload = { 'skuId': self.sku_id, } try: self.seckill_order_data[ self.sku_id] = self._get_seckill_order_data() except Exception as e: logger.info('抢购失败,无法获取生成订单的基本信息,接口返回:【{}】'.format(str(e))) return False logger.info('提交抢购订单...') headers = { 'User-Agent': self.user_agent, 'Host': 'marathon.jd.com', 'Referer': 'https://marathon.jd.com/seckill/seckill.action?skuId={0}&num={1}&rid={2}' .format(self.sku_id, self.seckill_num, int(time.time())), } resp = self.session.post(url=url, params=payload, data=self.seckill_order_data.get(self.sku_id), headers=headers) resp_json = None try: resp_json = parse_json(resp.text) except Exception as e: logger.info('抢购失败,返回信息:{}'.format(resp.text[0:128])) return False # 返回信息 # 抢购失败: # {'errorMessage': '很遗憾没有抢到,再接再厉哦。', 'orderId': 0, 'resultCode': 60074, 'skuId': 0, 'success': False} # {'errorMessage': '抱歉,您提交过快,请稍后再提交订单!', 'orderId': 0, 'resultCode': 60017, 'skuId': 0, 'success': False} # {'errorMessage': '系统正在开小差,请重试~~', 'orderId': 0, 'resultCode': 90013, 'skuId': 0, 'success': False} # 抢购成功: # {"appUrl":"xxxxx","orderId":820227xxxxx,"pcUrl":"xxxxx","resultCode":0,"skuId":0,"success":true,"totalMoney":"xxxxx"} if resp_json.get('success'): order_id = resp_json.get('orderId') total_money = resp_json.get('totalMoney') pay_url = 'https:' + resp_json.get('pcUrl') logger.info('抢购成功,订单号:{}, 总价:{}, 电脑端付款链接:{}'.format( order_id, total_money, pay_url)) if global_config.getRaw('messenger', 'enable') == 'true': success_message = "抢购成功,订单号:{}, 总价:{}, 电脑端付款链接:{}".format( order_id, total_money, pay_url) send_wechat(success_message) return True else: logger.info('抢购失败,返回信息:{}'.format(resp_json)) if global_config.getRaw('messenger', 'enable') == 'true': error_message = '抢购失败,返回信息:{}'.format(resp_json) send_wechat(error_message) return False
def __init__(self): # 初始化信息 self.session = get_session() self.sku_id = global_config.getRaw('config', 'sku_id') self.seckill_init_info = dict() self.seckill_url = dict() self.seckill_order_data = dict() self.timers = Timer() self.default_user_agent = global_config.getRaw('config', 'DEFAULT_USER_AGENT')
def send_wechat(message): """推送信息到微信""" url = 'http://sc.ftqq.com/{}.send'.format( global_config.getRaw('messenger', 'sckey')) payload = {"text": '抢购结果', "desp": message} headers = { 'User-Agent': global_config.getRaw('config', 'DEFAULT_USER_AGENT') } requests.get(url, params=payload, headers=headers)
def __init__(self, sleep_interval=0.5): # '2018-09-28 22:45:50.000' d = global_config.getRaw('config', 'buy_date'); if (d is None) or (str(d).strip()=="") or (str(d).strip()=="$BUY_DATE"): d = datetime.today().strftime('%Y-%m-%d') self.buy_time = datetime.strptime(d + ' ' + global_config.getRaw('config','buy_time'), "%Y-%m-%d %H:%M:%S.%f") self.buy_time_ms = int(time.mktime(self.buy_time.timetuple()) * 1000.0 + self.buy_time.microsecond / 1000) self.sleep_interval = sleep_interval self.diff_time = self.local_jd_time_diff()
def __init__(self): # '2018-09-28 22:45:50.000' self.buy_time = datetime.strptime( global_config.getRaw('config', 'buy_time'), "%Y-%m-%d %H:%M:%S.%f") self.buy_time_ms = int( time.mktime(self.buy_time.timetuple()) * 1000.0 + self.buy_time.microsecond / 1000) self.sleep_interval = float( global_config.getRaw('config', 'sleep_time')) self.diff_time = self.local_jd_time_diff()
def _get_seckill_order_data(self): """生成提交抢购订单所需的请求体参数 :return: 请求体参数组成的dict """ logger.info('生成提交抢购订单所需参数...') # 获取用户秒杀初始化信息 try: self.seckill_init_info[self.sku_id] = self._get_seckill_init_info() init_info = self.seckill_init_info.get(self.sku_id) if init_info == None: return None default_address = init_info['addressList'][0] # 默认地址dict invoice_info = init_info.get('invoiceInfo', {}) # 默认发票信息dict, 有可能不返回 token = init_info['token'] data = { 'skuId': self.sku_id, 'num': 1, 'addressId': default_address['id'], 'yuShou': 'true', 'isModifyAddress': 'false', 'name': default_address['name'], 'provinceId': default_address['provinceId'], 'cityId': default_address['cityId'], 'countyId': default_address['countyId'], 'townId': default_address['townId'], 'addressDetail': default_address['addressDetail'], 'mobile': default_address['mobile'], 'mobileKey': default_address['mobileKey'], 'email': default_address.get('email', ''), 'postCode': '', 'invoiceTitle': invoice_info.get('invoiceTitle', -1), 'invoiceCompanyName': '', 'invoiceContent': invoice_info.get('invoiceContentType', 1), 'invoiceTaxpayerNO': '', 'invoiceEmail': '', 'invoicePhone': invoice_info.get('invoicePhone', ''), 'invoicePhoneKey': invoice_info.get('invoicePhoneKey', ''), 'invoice': 'true' if invoice_info else 'false', 'password': '', 'codTimeType': 3, 'paymentType': 4, 'areaCode': '', 'overseas': 0, 'phone': '', 'eid': global_config.getRaw('config', 'eid'), 'fp': global_config.getRaw('config', 'fp'), 'token': token, 'pru': '' } return data except Exception as e: logger.error('获取用户秒杀初始化信息失败{0},正在重试...'.format(e)) return None
def get_session(): # 初始化session session = requests.session() session.headers = {"User-Agent": global_config.getRaw('config', 'DEFAULT_USER_AGENT'), "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", "Connection": "keep-alive"} checksession = requests.session() checksession.headers = {"User-Agent": global_config.getRaw('config', 'DEFAULT_USER_AGENT'), "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", "Connection": "keep-alive"} # 获取cookies保存到session session.cookies = get_cookies() return session
def __init__(self): # 初始化信息 self.session = get_session() self.sku_id = global_config.getRaw('config', 'sku_id') self.seckill_init_info = dict() self.seckill_url = dict() self.seckill_order_data = dict() self.timers = Timer() self.default_user_agent = global_config.getRaw( 'config', 'DEFAULT_USER_AGENT') self.is_login = False self.time_diff = 0.1 self.nick_name = '' print("京东时间:%s\n本地时间:%s" % (datetime.fromtimestamp(self.getJdTime()), datetime.now()))
def __init__(self, sleep_interval=0.5): # '2018-09-28 22:45:50.000' self.tomorrow = (date.today() + timedelta(days=1)).strftime( "%Y-%m-%d") + " " + global_config.getRaw('config', 'buy_time') self.today = date.today().strftime( "%Y-%m-%d") + " " + global_config.getRaw('config', 'buy_time') self.buy_time = datetime.strptime(self.today, "%Y-%m-%d %H:%M:%S.%f") if self.jd_diff() < 0: self.buy_time = datetime.strptime(self.tomorrow, "%Y-%m-%d %H:%M:%S.%f") self.buy_time_ms = int( time.mktime(self.buy_time.timetuple()) * 1000.0 + self.buy_time.microsecond / 1000) self.sleep_interval = sleep_interval self.diff_time = self.local_jd_time_diff()
def _get_qrcode(self): """ 缓存并展示登录二维码 :return: """ url = 'https://passport.suning.com/ids/qrLoginUuidGenerate.htm?image=true&yys=%s' % str( time.time() * 1000)[:-5] headers = { 'User-Agent': self.spider_session.get_user_agent(), 'Referer': 'https://passport.suning.com/ids/login', } logger.info('登录二维码地址: %s' % url) resp = self.session.get(url=url, headers=headers) if not response_status(resp): logger.info('获取二维码失败') return False save_image(resp, self.qrcode_img_file) logger.info('二维码获取成功,请打开苏宁APP扫描') open_image(self.qrcode_img_file) if global_config.getRaw('messenger', 'email_enable') == 'true': email.send('二维码获取成功,请打开京东APP扫描', "<img src='cid:qr_code.png'>", [email.mail_user], 'qr_code.png') return True
def __init__(self, mail_user, mail_pwd, mail_host=''): if global_config.getRaw('messenger', 'email_enable') == 'false': return smtpObj = smtplib.SMTP() # 没传会自动判断 判断不出来默认QQ邮箱 if mail_host: self.mail_host = mail_host elif mail_user.endswith('163.com'): self.mail_host = 'smtp.163.com' elif mail_user.endswith(('sina.com', 'sina.cn')): self.mail_host = 'smtp.163.com' elif mail_user.endswith('qq.com'): self.mail_host = 'smtp.qq.com' elif mail_user.endswith('sohu.com'): self.mail_host = 'smtp.sohu.com' else: self.mail_host = 'smtp.qq.com' self.mail_user = mail_user self.is_login = False try: smtpObj.connect(mail_host, 25) smtpObj.login(mail_user, mail_pwd) self.is_login = True except Exception as e: logger.info('邮箱登录失败!', e) self.smtpObj = smtpObj
def _get_qrcode(self): """ 缓存并展示登录二维码 :return: """ url = 'https://qr.m.jd.com/show' payload = { 'appid': 133, 'size': 300, 't': str(int(time.time() * 1000)), } headers = { 'User-Agent': self.spider_session.get_user_agent(), 'Referer': 'https://passport.jd.com/new/login.aspx', } resp = self.session.get(url=url, headers=headers, params=payload) if not response_status(resp): logger.info('获取二维码失败') return False save_image(resp, self.qrcode_img_file) logger.info('二维码获取成功,请打开京东APP扫描') open_image(add_bg_for_qr(self.qrcode_img_file)) if global_config.getRaw('messenger', 'email_enable') == 'true': email.send('二维码获取成功,请打开京东APP扫描', "<img src='cid:qr_code.png'>", [email.mail_user], 'qr_code.png') return True
def get_sku_title(self): """获取商品名称""" url = 'https://item.jd.com/{}.html'.format(global_config.getRaw('config', 'sku_id')) resp = self.session.get(url).content x_data = etree.HTML(resp) sku_title = x_data.xpath('/html/head/title/text()') return sku_title[0]
def open_image(image_file): jump_url = None if os.name == "nt": os.system('start ' + image_file) # for Windows else: is_showed = False # 使用zbar解析二维码 qr_url = os.popen("zbarimg " + image_file).read() if qr_url: jump_url = qr_url.replace('QR-Code:', '').strip() # 使用命令行直接展示二维码 if os.system("qrencode '" + qr_url + "' -o - -t UTF8") == 0: is_showed = True print("\n") if not is_showed: jump_url = 'scan' if not jump_url else jump_url if os.uname()[0] == "Linux": if "deepin" in os.uname()[2]: os.system("deepin-image-viewer " + image_file) # for deepin else: os.system("eog " + image_file) else: os.system("open " + image_file) # for Mac if jump_url and global_config.getRaw('messenger', 'bark_enable') == 'true': send_bark('二维码获取成功,请打开京东APP扫描', jump_url)
def init_time(self, t=None): # '2018-09-28 22:45:50' t = global_config.getRaw('config', 'buy_time') if not t else t self.buy_time = datetime.strptime(t, "%Y-%m-%d %H:%M:%S") self.buy_time_ms = int( time.mktime(self.buy_time.timetuple()) * 1000.0 + self.buy_time.microsecond / 1000) - 500
def make_reserve(self): """商品预约""" logger.info('用户:{}'.format(self.get_user_info())) logger.info('商品名称:{}'.format(self.get_sku_title())) url = 'https://yushou.jd.com/youshouinfo.action?' payload = { 'callback': 'fetchJSON', 'sku': self.sku_id, '_': str(int(time.time() * 1000)), } headers = { 'User-Agent': self.default_user_agent, 'Referer': 'https://item.jd.com/{}.html'.format(self.sku_id), } resp = self.session.get(url=url, params=payload, headers=headers) resp_json = parse_json(resp.text) reserve_url = resp_json.get('url') self.timers.start() while True: try: self.session.get(url='https:' + reserve_url) logger.info('预约成功,已获得抢购资格 / 您已成功预约过了,无需重复预约') if global_config.getRaw('messenger', 'enable') == 'true': success_message = "预约成功,已获得抢购资格 / 您已成功预约过了,无需重复预约" send_wechat(success_message) break except Exception as e: logger.error('预约失败正在重试...')
def make_reserve(self): """商品预约""" logger.info('商品名称:{}'.format(get_sku_title())) url = 'https://yushou.jd.com/youshouinfo.action?' payload = { 'callback': 'fetchJSON', 'sku': self.sku_id, '_': str(int(time.time() * 1000)), } headers = { 'User-Agent': self.default_user_agent, 'Referer': 'https://item.jd.com/{}.html'.format(self.sku_id), } print("payload" + json.dumps(payload) + "\n" + "headers" + json.dumps(headers)) resp = self.session.get(url=url, params=payload, headers=headers) print(resp) resp_json = parse_json(resp.text) reserve_url = resp_json.get('url') for flag in range(10): try: self.session.get(url='https:' + reserve_url) logger.info('预约成功,已获得抢购资格 / 您已成功预约过了,无需重复预约') if global_config.getRaw('messenger', 'enable') == 'true': success_message = "预约成功,已获得抢购资格 / 您已成功预约过了,无需重复预约" send_wechat(success_message) break except Exception as e: logger.error('预约失败正在重试...' + str(flag) + " " + str(e)) sleep(random.randint(1, 3)) sys.exit(1)
def __init__(self): self.spider_session = SpiderSession() self.spider_session.load_cookies_from_local() self.qrlogin = QrLogin(self.spider_session) # 初始化信息 self.sku_id = global_config.getRaw('config', 'sku_id') self.seckill_num = global_config.getRaw('config', 'seckill_num') self.seckill_init_info = dict() self.seckill_url = dict() self.seckill_order_data = dict() self.timers = Timer() self.session = self.spider_session.get_session() self.user_agent = self.spider_session.user_agent self.nick_name = None
def __init__(self, sleep_interval=0.5): # '2018-09-28 22:45:50.000' # buy_time = 2020-12-22 09:59:59.500 localtime = time.localtime(time.time()) buy_time_everyday = global_config.getRaw('config', 'buy_time').__str__() self.buy_time_everyday = buy_time_everyday last_purchase_time_everyday = global_config.getRaw('config', 'last_purchase_time').__str__() last_reserve_time_everyday = global_config.getRaw('config', 'last_reserve_time').__str__() # 最后购买时间 last_purchase_time = datetime.strptime( localtime.tm_year.__str__() + '-' + localtime.tm_mon.__str__() + '-' + localtime.tm_mday.__str__() + ' ' + last_purchase_time_everyday, "%Y-%m-%d %H:%M:%S.%f") # 购买时间 buy_time_config = datetime.strptime( localtime.tm_year.__str__() + '-' + localtime.tm_mon.__str__() + '-' + localtime.tm_mday.__str__() + ' ' + buy_time_everyday, "%Y-%m-%d %H:%M:%S.%f") # 预约时间 reserve_time_config = datetime.strptime( localtime.tm_year.__str__() + '-' + localtime.tm_mon.__str__() + '-' + localtime.tm_mday.__str__() + ' ' + last_reserve_time_everyday, "%Y-%m-%d %H:%M:%S.%f") if time.mktime(localtime) < time.mktime(buy_time_config.timetuple()): # 取正确的购买时间 self.buy_time = buy_time_config elif time.mktime(localtime) > time.mktime(last_purchase_time.timetuple()): # 取明天的时间 购买时间 self.buy_time = datetime.strptime( localtime.tm_year.__str__() + '-' + localtime.tm_mon.__str__() + '-' + ( localtime.tm_mday + 1).__str__() + ' ' + buy_time_everyday, "%Y-%m-%d %H:%M:%S.%f") else: # 直接是购买时间 self.buy_time = buy_time_config print("购买时间:{}".format(self.buy_time)) print("预约时间:{}".format(reserve_time_config)) self.buy_time_ms = int(time.mktime(self.buy_time.timetuple()) * 1000.0 + self.buy_time.microsecond / 1000) self.reserve_time_ms = int( time.mktime(reserve_time_config.timetuple()) * 1000.0 + reserve_time_config.microsecond / 1000) self.sleep_interval = sleep_interval self.diff_time = self.local_jd_time_diff()
def __init__(self, sleep_interval=0.5): self.buy_time = 0 self.buy_time_ms = 0 self.start_time = 0 self.init_time() self.diff_time = self.local_jd_time_diff() self.sleep_interval = sleep_interval self.max_duration = int( global_config.getRaw('config', 'seckill_duration'))
def seckill_by_proc_pool_xiaomi(self, work_count=8): """ 多进程进行抢购 work_count:进程数量 """ self.sku_id = global_config.getRaw('config', 'xiaomi_sku_id') with ProcessPoolExecutor(work_count) as pool: for i in range(work_count): pool.submit(self.seckill)
def get_cookies(): """解析cookies内容并添加到cookiesJar""" manual_cookies = {} for item in global_config.getRaw('config','cookies_String').split(';'): name, value = item.strip().split('=', 1) # 用=号分割,分割1次 manual_cookies[name] = value # 为字典cookies添加内容 cookiesJar = requests.utils.cookiejar_from_dict(manual_cookies, cookiejar=None, overwrite=True) return cookiesJar
def __init__(self, sleep_interval=0.5): # '2018-09-28 22:45:50.000' # 获取本地今日年月日+空格+需要抢购的时间 now_time = datetime.now().strftime('%Y-%m-%d') get_buytime = global_config.getRaw('config','buy_time') self.real_bugtime = now_time + " " + get_buytime self.buy_time = datetime.strptime(self.real_bugtime, "%Y-%m-%d %H:%M:%S.%f") self.buy_time_ms = int(time.mktime(self.buy_time.timetuple()) * 1000.0 + self.buy_time.microsecond / 1000) self.sleep_interval = sleep_interval self.diff_time = self.local_jd_time_diff()
def __init__(self): self.spider_session = SpiderSession() self.spider_session.load_cookies_from_local() self.qrlogin = QrLogin(self.spider_session) # 初始化信息 self.sku_id = global_config.getRaw('config', 'sku_id') self.seckill_num = 2 self.seckill_init_info = dict() self.seckill_url = dict() self.seckill_order_data = dict() self.buy_time = datetime.strptime( global_config.getRaw('config', 'buy_time'), "%Y-%m-%d %H:%M:%S.%f") self.timers = Timer() self.session = self.spider_session.get_session() self.user_agent = self.spider_session.user_agent self.nick_name = None self.user_name = None self.product_name = None
def __init__(self, sleep_interval=0.5): # '2018-09-28 22:45:50.000' # buy_time = 2020-12-22 09:59:59.500 buy_time_everyday = global_config.getRaw('config', 'buy_time').__str__() localtime = time.localtime(time.time()) self.buy_time = datetime.strptime( localtime.tm_year.__str__() + '-' + localtime.tm_mon.__str__() + '-' + localtime.tm_mday.__str__() + ' ' + buy_time_everyday, "%Y-%m-%d %H:%M:%S.%f") self.buy_time_ms = int(time.mktime(self.buy_time.timetuple()) * 1000.0 + self.buy_time.microsecond / 1000) self.sleep_interval = sleep_interval self.diff_time = self.local_jd_time_diff()
def make_reserve(self): """商品预约""" logger.info('商品名称:{}'.format(self.get_sku_title())) url = 'https://yushou.jd.com/youshouinfo.action?' payload = { 'callback': 'fetchJSON', 'sku': self.sku_id, '_': str(int(time.time() * 1000)), } headers = { 'User-Agent': self.user_agent, 'Referer': 'https://item.jd.com/{}.html'.format(self.sku_id), } resp = self.session.get(url=url, params=payload, headers=headers) resp_json = parse_json(resp.text) reserve_url = resp_json.get('url') # self.timers.start() while True: try: self.session.get(url='https:' + reserve_url) resp_text = self.session.get(url='https:' + reserve_url).text resp_html = etree.HTML(resp_text) result_msg = "".join([ t.strip() for t in resp_html.xpath( "//div[@class='bd-right']/./*[@class='bd-right-result']/text()" ) ]) if len( resp_html.xpath( "//div[@class='bd-right']/./*[@class='bd-right-result']/text()" )) > 0 else "未匹配到预约消息" if "预约成功" in resp_text: logger.info('预约成功,已获得抢购资格 / 您已成功预约过了,无需重复预约') logger.info(result_msg) self.reserve_statue = True if global_config.getRaw('messenger', 'enable') == 'true': success_message = "预约成功,已获得抢购资格 / 您已成功预约过了,无需重复预约" send_wechat(success_message) break elif "预约失败" in resp_text: logger.info('预约失败,超过最大购买数量/已经预约过!') logger.info(result_msg) self.reserve_statue = True break else: logger.info('预约返回其他未知提示!') logger.info(result_msg) self.reserve_statue = True break except Exception as e: logger.error('预约失败正在重试...', e)
def seckill_canstill_running(self): """用config.ini文件中的continue_time加上函数buytime_get()获取到的start_buy_local_time, 来判断抢购的任务是否可以继续运行 """ buy_time = self.timers.buytime_get() continue_time = int(global_config.getRaw('config', 'continue_time')) stop_time = datetime.strptime(( buy_time + timedelta(minutes=continue_time)).strftime("%Y-%m-%d %H:%M:%S.%f"), "%Y-%m-%d %H:%M:%S.%f") current_time = datetime.now() if current_time > stop_time: self.running_flag = False logger.info('超过允许的运行时间,任务结束。') sys.exit(0)
def make_reserve(self): """优惠券领取""" activity_id = '3S53g25ji4mzEGVoeRiXxpmpAYjs' args = 'key%3D3CF9A614611B32207E8BBC194F3E5B7738A155696C5E3F56E9E0E07235F17D90F303B26F9C35123E006713687B01391C_babel%2CroleId%3DA0BAF3B922198E20E8A068B1FFD943ED_babel' # 在config.ini配置自己的 eid, fp eid = global_config.getRaw('config', 'eid') fp = global_config.getRaw('config', 'fp') headers = { 'User-Agent': self.user_agent, 'Referer': 'https://pro.jd.com/', } # https://api.m.jd.com/client.action?functionId=newBabelAwardCollection&body=%7B%22activityId%22%3A%223S53g25ji4mzEGVoeRiXxpmpAYjs%22%2C%22scene%22%3A%221%22%2C%22args%22%3A%22key%3D3CF9A614611B32207E8BBC194F3E5B7738A155696C5E3F56E9E0E07235F17D90F303B26F9C35123E006713687B01391C_babel%2CroleId%3DA0BAF3B922198E20E8A068B1FFD943ED_babel%22%2C%22eid%22%3A%222LAFNHDGXK7DFUHSL7LM4ZJQYEH2HNFL6C4VKXRWHOQCHOF6QU5Z4OLVCZW2SVA7PO2JT5JFVY2GX2UVALF7FZ4MNQ%22%2C%22fp%22%3A%22e3e04bcb478bc50f19f40382fa45298f%22%2C%22pageClick%22%3A%22Babel_Coupon%22%2C%22mitemAddrId%22%3A%22%22%2C%22geo%22%3A%7B%22lng%22%3A%22%22%2C%22lat%22%3A%22%22%7D%7D&screen=750*1334&client=wh5&clientVersion=1.0.0&sid=&uuid=&area=&loginType=3&callback=jsonp1 url = 'https://api.m.jd.com/client.action?functionId=newBabelAwardCollection&body=%7B%22activityId%22%3A%22' + activity_id + '%22%2C%22scene%22%3A%221%22%2C%22args%22%3A%22' + args + '%22%2C%22eid%22%3A' + eid + '%2C%22fp%22%3A' + fp + '%2C%22pageClick%22%3A%22Babel_Coupon%22%2C%22mitemAddrId%22%3A%22%22%2C%22geo%22%3A%7B%22lng%22%3A%22%22%2C%22lat%22%3A%22%22%7D%7D&screen=750*1334&client=wh5&clientVersion=1.0.0&sid=&uuid=&area=&loginType=3&callback=jsonp1' resp = self.session.get(url=url, params=None, headers=headers) print(resp.url) resp_json = parse_json(resp.text) code = resp_json.get('code') if code == '1': logger.info('优惠券领取失败: {}'.format(resp_json.get('errmsg'))) if code == '0': logger.info('优惠券领取结果: {}, {}'.format(resp_json.get('msg'), resp_json.get('subCodeMsg'))) self.timers.start() break_flag = False return break_flag
def make_reserve(self): """商品预约""" logger.info('商品名称:{}'.format(self.get_sku_title())) url = 'https://yushou.jd.com/youshouinfo.action?' payload = { 'callback': 'fetchJSON', 'sku': self.sku_id, '_': str(int(time.time() * 1000)), } headers = { 'User-Agent': self.user_agent, 'Referer': 'https://item.jd.com/{}.html'.format(self.sku_id), } resp = self.session.get(url=url, params=payload, headers=headers) resp_json = parse_json(resp.text) reserve_url = resp_json.get('url') self.timers.start() while True: try: self.session.get(url='https:' + reserve_url) logger.info('预约成功,已获得抢购资格 / 您已成功预约过了,无需重复预约') requests.post( "https://sc.ftqq.com/SCU67992Tb6d106e75a7e8fa6f00c53c9bf7f7bb05de8bce100ce2.send", data={ "text": "茅台预约成功啦", "desp": """茅台预约成功啦 ![image](https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1601019829813&di=f40ea308a5fb36b99d793cd74785b24c&imgtype=0&src=http%3A%2F%2Fpic.feizl.com%2Fupload%2Fallimg%2F170704%2F4881tnxkewt5mq.jpg) """ }) if global_config.getRaw('messenger', 'enable') == 'true': success_message = "预约成功,已获得抢购资格 / 您已成功预约过了,无需重复预约" send_wechat(success_message) requests.post( "https://sc.ftqq.com/SCU67992Tb6d106e75a7e8fa6f00c53c9bf7f7bb05de8bce100ce2.send", data={ "text": "茅台预约成功啦", "desp": """茅台预约成功啦 ![image](https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1601019829813&di=f40ea308a5fb36b99d793cd74785b24c&imgtype=0&src=http%3A%2F%2Fpic.feizl.com%2Fupload%2Fallimg%2F170704%2F4881tnxkewt5mq.jpg) """ }) break except Exception as e: logger.error('预约失败正在重试...')
def __init__(self, sleep_interval=0.5): # '2018-09-28 22:45:50.000' self.buy_time = datetime.strptime( global_config.getRaw('config', 'buy_time'), "%Y-%m-%d %H:%M:%S.%f") print(self.buy_time) print(type(self.buy_time)) self.sleep_interval = sleep_interval date_today = datetime.now().date() date_today_str = str(date_today) + " " # print(date_today_str) date_today_str = date_today_str + "10:00:00.100000" # print(date_today_str) self.buy_time = datetime.strptime(date_today_str, "%Y-%m-%d %H:%M:%S.%f")