def queryOrderWaitTime(self): """ 排队获取订单等待信息,每隔3秒请求一次,最高请求次数为20次! :return: """ num = 1 while True: _random = int(round(time.time() * 1000)) num += 1 if num > 30: print(u"超出排队时间,自动放弃,正在重新刷票") order_id = self.queryMyOrderNoComplete() # 排队失败,自动取消排队订单 if order_id: try: self.cancelNoCompleteMyOrder(order_id) except: print("取消未完成的订单失败") break try: data = {"random": _random, "tourFlag": "dc"} queryOrderWaitTimeUrl = self.confUrl["queryOrderWaitTimeUrl"] queryOrderWaitTimeResult = self.httpClint.send( queryOrderWaitTimeUrl, data) except ValueError: queryOrderWaitTimeResult = {} if queryOrderWaitTimeResult: if "status" in queryOrderWaitTimeResult and queryOrderWaitTimeResult[ "status"]: if "orderId" in queryOrderWaitTimeResult["data"] and \ queryOrderWaitTimeResult["data"]["orderId"] is not None: sendEmail( u"恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306," u"访问‘未完成订单’,在30分钟内完成支付!".format( queryOrderWaitTimeResult["data"]["orderId"])) raise ticketIsExitsException( u"恭喜您订票成功,订单号为:{0}, " u"请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format( queryOrderWaitTimeResult["data"]["orderId"])) elif "msg" in queryOrderWaitTimeResult[ "data"] and queryOrderWaitTimeResult["data"]["msg"]: print queryOrderWaitTimeResult["data"]["msg"] break elif "waitTime" in queryOrderWaitTimeResult[ "data"] and queryOrderWaitTimeResult["data"][ "waitTime"]: print(u"排队等待时间预计还剩 {0} ms".format( 0 - queryOrderWaitTimeResult["data"]["waitTime"])) else: print("正在等待中") elif "messages" in queryOrderWaitTimeResult and queryOrderWaitTimeResult[ "messages"]: print(u"排队等待失败: " + queryOrderWaitTimeResult["messages"]) else: print(u"第{}次排队中,请耐心等待".format(num + 1)) else: print(u"排队中") time.sleep(2) else: print(ticketNumOutException(u"订单提交失败!,正在重新刷票"))
def sendQueryOrderWaitTime(self): """ 排队获取订单等待信息,每隔3秒请求一次,最高请求次数为20次! :return: """ num = 1 while True: num += 1 if num > ticket.OUT_NUM: print(ticket.WAIT_OUT_NUM) order_id = self.queryMyOrderNoComplete() # 排队失败,自动取消排队订单 if order_id: self.cancelNoCompleteMyOrder(order_id) break try: queryOrderWaitTimeUrl = copy.deepcopy( self.session.urls["queryOrderWaitTimeUrl"]) queryOrderWaitTimeUrl["req_url"] = queryOrderWaitTimeUrl[ "req_url"].format(int(round(time.time() * 1000))) queryOrderWaitTimeResult = self.session.httpClint.send( queryOrderWaitTimeUrl) except ValueError: queryOrderWaitTimeResult = {} if queryOrderWaitTimeResult: if queryOrderWaitTimeResult.get("status", False): data = queryOrderWaitTimeResult.get("data", False) if data and data.get("orderId", ""): sendIFTTT( ticket.WAIT_ORDER_SUCCESS.format( data.get("orderId", ""))) sendEmail( ticket.WAIT_ORDER_SUCCESS.format( data.get("orderId", ""))) sendPushBear( ticket.WAIT_ORDER_SUCCESS.format( data.get("orderId", ""))) raise ticketIsExitsException( ticket.WAIT_ORDER_SUCCESS.format( data.get("orderId"))) elif data.get("msg", False): print(data.get("msg", "")) break elif data.get("waitTime", False): print( ticket.WAIT_ORDER_CONTINUE.format( 0 - data.get("waitTime", False))) else: pass elif queryOrderWaitTimeResult.get("messages", False): print( ticket.WAIT_ORDER_FAIL.format( queryOrderWaitTimeResult.get("messages", ""))) else: print(ticket.WAIT_ORDER_NUM.format(num + 1)) else: pass time.sleep(2) else: print(ticketNumOutException(ticket.WAIT_ORDER_SUB_FAIL))
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 queryOrderWaitTime(self): """ 排队获取订单等待信息,每隔3秒请求一次,最高请求次数为20次! :return: """ # queryOrderWaitTimeUrl = "https://kyfw.12306.cn/otn/confirmPassenger/queryOrderWaitTime" # data = { # "random": "{0}{1}".format(int(time.time()), random.randint(1, 9)), # "tourFlag": "dc", # "REPEAT_SUBMIT_TOKEN": self.get_token(), # } num = 1 while True: _random = int(round(time.time() * 1000)) num += 1 if num > 30: print("超出排队时间,自动放弃,正在重新刷票") break try: queryOrderWaitTimeUrl = "https://kyfw.12306.cn/otn/confirmPassenger/queryOrderWaitTime?random={0}&tourFlag=dc&_json_att=&REPEAT_SUBMIT_TOKEN={1}".format(_random, self.get_token()) queryOrderWaitTimeResult = json.loads(myurllib2.get(queryOrderWaitTimeUrl)) except ValueError: queryOrderWaitTimeResult = {} if queryOrderWaitTimeResult: if "status" in queryOrderWaitTimeResult and queryOrderWaitTimeResult["status"]: if "orderId" in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["orderId"] is not None: sendEmail("恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(queryOrderWaitTimeResult["data"]["orderId"])) raise ticketIsExitsException("恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(queryOrderWaitTimeResult["data"]["orderId"])) elif "msg" in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["msg"]: print queryOrderWaitTimeResult["data"]["msg"] break elif "waitTime"in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["waitTime"]: print("排队等待时间预计还剩 {0} ms".format(0-queryOrderWaitTimeResult["data"]["waitTime"])) else: print ("正在等待中") elif "messages" in queryOrderWaitTimeResult and queryOrderWaitTimeResult["messages"]: print("排队等待失败: " + queryOrderWaitTimeResult["messages"]) else: print("第{}次排队中,请耐心等待".format(num)) else: print("排队中") time.sleep(1) order_id = self.queryMyOrderNoComplete() # 尝试查看订单列表,如果有订单,则判断成功,不过一般可能性不大 if order_id: sendEmail("恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(order_id)) raise ticketIsExitsException("恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(order_id)) else: print(ticketNumOutException("订单提交失败!,正在重新刷票"))
def sendQueryOrderWaitTime(self): """ 排队获取订单等待信息,每隔3秒请求一次,最高请求次数为20次! :return: """ num = 1 while True: num += 1 if num > ticket.OUT_NUM: print(ticket.WAIT_OUT_NUM) order_id = self.queryMyOrderNoComplete() # 排队失败,自动取消排队订单 if order_id: self.cancelNoCompleteMyOrder(order_id) break try: queryOrderWaitTimeUrl = copy.deepcopy(self.session.urls["queryOrderWaitTimeUrl"]) queryOrderWaitTimeUrl["req_url"] = queryOrderWaitTimeUrl["req_url"].format(int(round(time.time() * 1000))) queryOrderWaitTimeResult = self.session.httpClint.send(queryOrderWaitTimeUrl) except ValueError: queryOrderWaitTimeResult = {} if queryOrderWaitTimeResult: if queryOrderWaitTimeResult.get("status", False): data = queryOrderWaitTimeResult.get("data", False) if data and data.get("orderId", ""): sendEmail(ticket.WAIT_ORDER_SUCCESS.format( data.get("orderId", ""))) raise ticketIsExitsException(ticket.WAIT_ORDER_SUCCESS.format( data.get("orderId"))) elif data.get("msg", False): print(data.get("msg", "")) break elif data.get("waitTime", False): print(ticket.WAIT_ORDER_CONTINUE.format(0 - data.get("waitTime", False))) else: pass elif queryOrderWaitTimeResult.get("messages", False): print(ticket.WAIT_ORDER_FAIL.format(queryOrderWaitTimeResult.get("messages", ""))) else: print(ticket.WAIT_ORDER_NUM.format(num + 1)) else: pass time.sleep(2) else: print(ticketNumOutException(ticket.WAIT_ORDER_SUB_FAIL))
def queryOrderWaitTime(self): """ 排队获取订单等待信息,每隔3秒请求一次,最高请求次数为20次! :return: """ num = 1 while True: _random = int(round(time.time() * 1000)) num += 1 if num > 30: print(u"超出排队时间,自动放弃,正在重新刷票") order_id = self.queryMyOrderNoComplete() # 排队失败,自动取消排队订单 if order_id: self.cancelNoCompleteMyOrder(order_id) break try: data = {"random": _random, "tourFlag": "dc"} queryOrderWaitTimeUrl = self.confUrl["queryOrderWaitTimeUrl"] queryOrderWaitTimeResult = self.httpClint.send(queryOrderWaitTimeUrl, data) except ValueError: queryOrderWaitTimeResult = {} if queryOrderWaitTimeResult: if "status" in queryOrderWaitTimeResult and queryOrderWaitTimeResult["status"]: if "orderId" in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["orderId"] is not None: sendEmail(u"恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(queryOrderWaitTimeResult["data"]["orderId"])) raise ticketIsExitsException(u"恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(queryOrderWaitTimeResult["data"]["orderId"])) elif "msg" in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["msg"]: print queryOrderWaitTimeResult["data"]["msg"] break elif "waitTime"in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["waitTime"]: print(u"排队等待时间预计还剩 {0} ms".format(0-queryOrderWaitTimeResult["data"]["waitTime"])) else: print ("正在等待中") elif "messages" in queryOrderWaitTimeResult and queryOrderWaitTimeResult["messages"]: print(u"排队等待失败: " + queryOrderWaitTimeResult["messages"]) else: print(u"第{}次排队中,请耐心等待".format(num+1)) else: print(u"排队中") time.sleep(2) else: print(ticketNumOutException(u"订单提交失败!,正在重新刷票"))
def testEmail(self): """ 实测邮箱是否可用 :return: """ sendEmail("订票小助手测试一下")
def Email(): sendEmail(u"订票小助手测试一下")
def Email(): sendEmail(u"订票代码测试一下")
import argparse import sys def parser_arguments(argv): """ 不应该在这里定义,先放在这里 :param argv: :return: """ parser = argparse.ArgumentParser() parser.add_argument("operate", type=str, help="r: 运行抢票程序, c: 过滤cdn, t: 测试邮箱和server酱,server酱需要打开开关") return parser.parse_args(argv) if __name__ == '__main__': args = parser_arguments(sys.argv[1:]) if args.operate == "r": from init import select_ticket_info select_ticket_info.select().main() elif args.operate == "t": from config.emailConf import sendEmail from config.serverchanConf import sendServerChan sendEmail(u"订票小助手测试一下") sendServerChan("订票小助手测试一下") elif args.operate == "c": from agency.cdn_utils import filterCdn filterCdn()
def testEmail(self): """ 实wrwwrwvd :return: """ sendEmail(u"订票小助手测试一下")