def sendPushBear(msg): """ pushBear微信通知 :param str: 通知内容 content :return: """ conf = _get_yaml() user = _get_yaml()["set"]["12306account"][0]["user"] if conf["pushbear_conf"][ "is_pushbear"] and conf["pushbear_conf"]["send_key"].strip() != "": try: sendPushBearUrls = urls.get("Pushbear") data = { "sendkey": conf["pushbear_conf"]["send_key"].strip(), "text": user + "购票成功通知", "desp": msg } httpClint = HTTPClient(0) sendPushBeaRsp = httpClint.send(sendPushBearUrls, data=data) if sendPushBeaRsp.get("code") is 0: print(u"已下发 pushbear 微信通知, 请查收") else: print(sendPushBeaRsp) except Exception as e: print(u"pushbear 配置有误 {}".format(e)) else: pass
def sendSubmitOrderRequest(self, ): submitOrderRequestRsp = self.session.httpClint.send(urls.get("SubmitOrderRequestRsp"), self.data_apr()) if not submitOrderRequestRsp.get("status") or not submitOrderRequestRsp.get("data", {}).get("flag"): print("".join(submitOrderRequestRsp.get("messages")) or submitOrderRequestRsp.get("validateMessages")) return pApi = passengerInitApi(self.session, self.secretList, self.tickerNo) pApi.sendPassengerInitApi()
def sendPushBear(msg): """ pushBear微信通知 :param str: 通知内容 content :return: """ conf = _get_yaml() if conf["pushbear_conf"][ "is_pushbear"] and conf["pushbear_conf"]["send_key"].strip() != "": try: sendPushBearUrls = urls.get("Pushbear") data = { "sendkey": conf["pushbear_conf"]["send_key"].strip(), "text": "易行购票成功通知,{}".format(time.strftime("%Y-%m-%d %H:%M:%S")), "desp": msg } httpClint = HTTPClient(0) sendPushBeaRsp = httpClint.send(sendPushBearUrls, data=data) if sendPushBeaRsp.get("code") is 0: print(u"已下发 pushbear 微信通知, 请查收") else: print(sendPushBeaRsp) except Exception as e: print(u"pushbear 配置有误 {}".format(e)) else: pass
def send_push_bear(msg): """ pushBear微信通知 :param msg: 通知内容 content :return: """ if TickerConfig.PUSHBEAR_CONF[ "is_pushbear"] and TickerConfig.PUSHBEAR_CONF["send_key"].strip( ) != "": try: send_push_bear_urls = urls.get("Pushbear") data = { "sendkey": TickerConfig.PUSHBEAR_CONF["send_key"].strip(), "text": "购票成功通知", "desp": msg } http_client = HTTPClient(0) send_push_bea_rsp = http_client.send(send_push_bear_urls, data=data) if send_push_bea_rsp.get("code") is 0: print(u"已下发 pushbear 微信通知, 请查收") else: print(send_push_bea_rsp) except Exception as e: print(u"pushbear 配置有误 {}".format(e)) else: pass
def getRandCode(is_auto_code, auto_code_type, result): """ 识别验证码 :return: 坐标 """ try: if is_auto_code: if auto_code_type == 1: print(u"打码兔已关闭, 如需使用自动识别,请使用如果平台 auto_code_type == 2") return elif auto_code_type == 2: Result = verify(result) return codexy(Ofset=Result, is_raw_input=False) elif auto_code_type == 3: print("您已设置使用云打码,但是服务器资源有限,请尽快改为本地打码") http = HTTPClient(0) Result = http.send(urls.get("autoVerifyImage"), {"imageFile": result}) if Result and Result.get("code") is 0: return codexy(Ofset=Result.get("data"), is_raw_input=False) else: img = Image.open('./tkcode.png') img.show() return codexy() except Exception as e: print(e)
def sendSubmitOrderRequest(self, ): submitOrderRequestRsp = self.session.httpClint.send(urls.get("SubmitOrderRequestRsp"), self.data_apr()) if not submitOrderRequestRsp.get("status") or not submitOrderRequestRsp.get("data", {}).get("flag"): print("".join(submitOrderRequestRsp.get("messages")) or submitOrderRequestRsp.get("validateMessages")) return confirm = confirmHB(self.secretList, self.session, self.tickerNo) confirm.sendChechFace()
def request_device_id(session): """ 获取加密后的浏览器特征 ID :return: """ params = { "algID": request_alg_id(session), "timestamp": int(time.time() * 1000) } params = dict(params, **_get_hash_code_params()) response = session.httpClint.send(urls.get("getDevicesId"), params=params) if response.find('callbackFunction') >= 0: result = response[18:-2] try: result = json.loads(result) session.httpClint.set_cookies([{ 'RAIL_EXPIRATION': result.get('exp'), 'RAIL_DEVICEID': result.get('dfp'), }]) session.cookies = [{ 'RAIL_EXPIRATION': result.get('exp'), 'RAIL_DEVICEID': result.get('dfp'), }] except: return False
def getDeviceId(self): """ 获取设备唯一表示 :return: """ homeRsp = self.httpClient.send(urls=urls.get("xiaomiHome")) deviceId = re.findall(r'deviceId = \'(.*)\';', homeRsp)[0] return deviceId
def request_alg_id(session): response = session.httpClint.send(urls.get("GetJS")) result = re.search(r'algID\\x3d(.*?)\\x26', response) try: return result.group(1) except (IndexError, AttributeError) as e: pass return ""
def sendChechFace(self): chechFaceRsp = self.session.httpClint.send(urls.get("chechFace"), self.data_apr()) if not chechFaceRsp.get("status"): print("".join(chechFaceRsp.get("messages")) or chechFaceRsp.get("validateMessages")) return g = getSuccessRate(self.session, self.secretList) g.sendSuccessRate()
def sendChechFace(self): ChechFaceRsp = self.session.httpClint.send(urls.get("confirmHB"), self.data_apr()) if not ChechFaceRsp.get("status"): print("".join(ChechFaceRsp.get("messages")) or ChechFaceRsp.get("validateMessages")) return queue = queryQueueByAfterNate(self.session) queue.sendQueryQueueByAfterNate()
def sendQueryQueueByAfterNate(self): for i in range(10): queryQueueByAfterNateRsp = self.session.httpClint.send(urls.get("queryQueue")) if not queryQueueByAfterNateRsp.get("status"): print("".join(queryQueueByAfterNateRsp.get("messages")) or queryQueueByAfterNateRsp.get("validateMessages")) time.sleep(1) else: sendEmail(ticket.WAIT_ORDER_SUCCESS) sendPushBear(ticket.WAIT_ORDER_SUCCESS) sendServerChan(ticket.WAIT_ORDER_SUCCESS) raise ticketIsExitsException(ticket.WAIT_AFTER_NATE_SUCCESS)
def sendChechFace(self): chechFaceRsp = self.session.httpClint.send(urls.get("chechFace"), self.data_apr()) if not chechFaceRsp.get("status"): print("".join(chechFaceRsp.get("messages")) or chechFaceRsp.get("validateMessages")) return data = chechFaceRsp["data"] if not data.get("face_flag") and data.get("face_check_code") == 14: """ 未通过人脸核验 """ raise ticketConfigException("通过人证一致性核验的用户及激活的“铁路畅行”会员可以提交候补需求,请您按照操作说明在铁路12306app.上完成人证核验") g = getSuccessRate(self.session, self.secretList) g.sendSuccessRate()
def sendSuccessRate(self): successRateRsp = self.session.httpClint.send( urls.get("getSuccessRate"), self.data_apr()) if not successRateRsp.get("status"): print("".join(successRateRsp.get("messages")) or successRateRsp.get("validateMessages")) return flag = successRateRsp.get("data", {}).get("flag")[0] train_no = flag.get("train_no") print(f"准备提交候补订单,{flag.get('info')}") submit = submitOrderRequestByAfterNate(self.session, self.secretList, train_no) submit.sendSubmitOrderRequest()
def sendServerChan(msg): try: sendPushBearUrls = urls.get("ServerChan") data = {"text": "自定义购票成功通知测试版本", "desp": msg} httpClint = HTTPClient(0) sendPushBeaRsp = httpClint.send(sendPushBearUrls, data=data) if sendPushBeaRsp.get("code") is 0: print(u"已下发 serverChan 微信通知, 请查收") else: print(sendPushBeaRsp) except Exception as e: print(u"serverChan 配置有误 {}".format(e)) pass
def login_conf(session): """ 判断登录是否需要验证码 :param session: :return: """ login_conf_url = urls.get("loginConf") login_conf_rsp = session.httpClient.send(urls=login_conf_url, data={}) if login_conf_rsp and login_conf_rsp.get( "data", {}).get("is_login_passCode") == "N": print(u"不需要验证码") return False else: print(u"需要验证码") return True
def sendPassengerInitApi(self): passengerInitApiRsp = self.session.httpClint.send( urls.get("passengerInitApi")) if not passengerInitApiRsp.get("status"): print("".join(passengerInitApiRsp.get("messages")) or passengerInitApiRsp.get("validateMessages")) return data = passengerInitApiRsp.get("data", {}) jzdhDateE = data.get("jzdhDateE") jzdhHourE = data.get("jzdhHourE").replace(":", "#") jzdhDate = f"{jzdhDateE}#{jzdhHourE}" print(f"当前候补日期为:{jzdhDateE} {jzdhHourE}") confirm = confirmHB(self.secretList, self.session, self.tickerNo, jzdhDate) confirm.sendChechFace()
def loginAysnSuggest(session, username, password): """ 登录接口 ps: 不需要验证码 :return: """ loginAysnSuggestUrls = urls.get("loginAysnSuggest") data = { "loginUserDTO.user_name": username, "userDTO.password": password } loginAysnSuggestRsp = session.httpClint.send(urls=loginAysnSuggestUrls, data=data) if loginAysnSuggestRsp and loginAysnSuggestRsp.get("httpstatus") is 200 and loginAysnSuggestRsp.get("data", {}).get("loginCheck") == "Y": print(u"登录成功") else: print(u"登录失败, {0} {1}".format("".join(loginAysnSuggestRsp.get("messages")), loginAysnSuggestRsp.get("validateMessages")))
def login(self, RouterPwd): """ 登录 :param RouterPwd: :return: """ secretRouterPwd = self.secretJs(RouterPwd) TPLinkRouterUrls = urls.get("TPLINK") data = {"method": "do", "login": {"password": secretRouterPwd}} loginRsp = self.httpClient.send(urls=TPLinkRouterUrls, data=json.dumps(data)) if loginRsp.get("error_code") is 0: print("路由器登录成功") self.stok = loginRsp.get("stok") else: print("TP_LINK路由器登录失败:{}".format(loginRsp))
def sendPassengerInitApi(self): passengerInitApiRsp = self.session.httpClint.send(urls.get("passengerInitApi")) if not passengerInitApiRsp.get("status"): print("".join(passengerInitApiRsp.get("messages")) or passengerInitApiRsp.get("validateMessages")) return data = passengerInitApiRsp.get("data", {}) jzdhDateE = data.get("jzdhDateE") if not data.get("jzdhHourE"): wrapcache.set(key=f"hb{self.tickerNo}", value=datetime.datetime.now(), timeout=TickerConfig.TICKET_BLACK_LIST_TIME * 60) print(f"获取当前候补日期失败,原因: {data.get('jzdhHourE')}") return jzdhHourE = data.get("jzdhHourE").replace(":", "#") jzdhDate = f"{jzdhDateE}#{jzdhHourE}" print(f"当前候补日期为:{jzdhDateE} {jzdhHourE}") confirm = confirmHB(self.secretList, self.session, self.tickerNo, jzdhDate) confirm.sendChechFace()
def sendChechFace(self): chechFaceRsp = self.session.httpClint.send(urls.get("chechFace"), self.data_apr()) if not chechFaceRsp.get("status"): print("".join(chechFaceRsp.get("messages")) or chechFaceRsp.get("validateMessages")) wrapcache.set(key=f"hb{self.train_no}", value=datetime.datetime.now(), timeout=TickerConfig.TICKET_BLACK_LIST_TIME * 60) return data = chechFaceRsp["data"] if not data.get("face_flag"): print("".join(chechFaceRsp.get("messages")) or chechFaceRsp.get("validateMessages")) if data.get("face_check_code") == "14": """ 未通过人脸核验 """ raise ticketConfigException( "通过人证一致性核验的用户及激活的“铁路畅行”会员可以提交候补需求,请您按照操作说明在铁路12306app.上完成人证核验" ) elif data.get("face_check_code") in ["12", "02"]: """ 系统忙,请稍后再试! """ print("系统忙,请稍后再试!") wrapcache.set(key=f"hb{self.train_no}", value=datetime.datetime.now(), timeout=TickerConfig.TICKET_BLACK_LIST_TIME * 60) elif data.get("face_check_code") in ["03", "13"]: """ 证件信息审核失败,请检查所填写的身份信息内容与原证件是否一致。 """ raise ticketConfigException("证件信息审核失败,请检查所填写的身份信息内容与原证件是否一致。") elif data.get("face_check_code") in ["01", "11"]: """ 证件信息正在审核中,请您耐心等待,审核通过后可继续完成候补操作。 """ print("证件信息正在审核中,请您耐心等待,审核通过后可继续完成候补操作。") wrapcache.set(key=f"hb{self.train_no}", value=datetime.datetime.now(), timeout=TickerConfig.TICKET_BLACK_LIST_TIME * 60) g = getSuccessRate(self.session, self.secretList) g.sendSuccessRate()
def sendChechFace(self): chechFaceRsp = self.session.httpClint.send(urls.get("chechFace"), self.data_apr()) if not chechFaceRsp.get("status"): print("".join(chechFaceRsp.get("messages")) or chechFaceRsp.get("validateMessages")) wrapcache.set(key=f"hb{self.train_no}", value=datetime.datetime.now(), timeout=TickerConfig.TICKET_BLACK_LIST_TIME * 60) return data = chechFaceRsp["data"] if not data.get("face_flag"): """ 未通过人脸核验 """ raise ticketConfigException( "通过人证一致性核验的用户及激活的“铁路畅行”会员可以提交候补需求,请您按照操作说明在铁路12306app.上完成人证核验") g = getSuccessRate(self.session, self.secretList) g.sendSuccessRate()
def login(self, RouterPwd): """ 登录 :param RouterPwd: :return: """ secretRouterPwd, nonce = self.secretJs(RouterPwd) TPLinkRouterUrls = urls.get("xiaomi") data = { "username": "******", "password": secretRouterPwd, "logtype": 2, "nonce": nonce, } loginRsp = self.httpClient.send(urls=TPLinkRouterUrls, data=data) if loginRsp.get("code") is 0: print("路由器登录成功") self.stok = loginRsp.get("url").split("web/")[0] else: print("小米路由器登录失败:{}".format(loginRsp))
def send_server_chan(msg): """ pushBear微信通知 :param msg: 通知内容 content :return: """ if (TickerConfig.SERVER_CHAN_CONF["is_server_chan"] and TickerConfig.SERVER_CHAN_CONF["secret"].strip() != ""): try: secret = TickerConfig.SERVER_CHAN_CONF["secret"].strip() send_server_chan_urls = urls.get("ServerChan") send_server_chan_urls["req_url"] += f'{secret}.send' params = {"text": "购票成功通知", "desp": msg} http_client = HTTPClient(0) send_server_chan_rsp = http_client.send(send_server_chan_urls, params=params) if send_server_chan_rsp.get("errno") == 0: print(u"已下发 Server酱 微信通知, 请查收") else: print(send_server_chan_rsp) except Exception as e: print(u"Server酱 配置有误 {}".format(e))
def sendVideoByDay(self): """ 获取2012.1.1日到昨天的每天电影数据 :return: """ GetMovieDayBoxOfficeListUrl = urls.get("GetMovieDayBoxOfficeList", "") _date = datetime.datetime.strftime( datetime.datetime.strptime( datetime.datetime.strftime( datetime.datetime.now(), '%Y-%m-%d', ), '%Y-%m-%d') + datetime.timedelta(days=-1), '%Y-%m-%d') data = { "r": random.random(), "UserID": "", "DateSort": "Day", "Date": _date, "sDate": _date, "eDate": _date, "Index": "102,201,202,205,203,211,221,222,606,225,251,801,604", "Line": "", "City": "", "CityLevel": "", "ServicePrice": 1, "PageIndex": 1, "PageSize": 40, "Order": 201, "OrderType": "DESC" } GetMovieDayBoxOfficeListRsp = self.httpClint.send( urls=GetMovieDayBoxOfficeListUrl, data=data) GetMovieDayBoxOfficeListData = GetMovieDayBoxOfficeListRsp["Data"][ "Table2"] self.mysqlConn.insert_video_day(GetMovieDayBoxOfficeListData, _date, self.redisConn)