diff --git a/UnitTest/TestAll.py b/UnitTest/TestAll.py index 17eb608..8e946fb 100644 --- a/UnitTest/TestAll.py +++ b/UnitTest/TestAll.py @@ -6,6 +6,7 @@ import requests from agency.agency_tools import proxy from config.emailConf import sendEmail +from config.pushbearConf import sendPushBear def _set_header_default(): @@ -38,6 +39,13 @@ class testAll(unittest.TestCase): :return: """ sendEmail("订票小助手测试一下") + + def testPushbear(self): + """ + 实测pushbear是否可用 + :return: + """ + sendPushBear("pushbear 微信通知测试一下") # def testConfig(self): # """ diff --git a/config/pushbearConf.py b/config/pushbearConf.py new file mode 100644 index 0000000..dd24cc9 --- /dev/null +++ b/config/pushbearConf.py @@ -0,0 +1,26 @@ +# -*- coding: utf8 -*- +__author__ = 'kongkongyzt' +import requests +from config.ticketConf import _get_yaml + +PUSH_BEAR_API_PATH = "https://pushbear.ftqq.com/sub" + +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: + requests.get("{}?sendkey={}&text=来自12306抢票助手的通知&desp={}".format(PUSH_BEAR_API_PATH, conf["pushbear_conf"]["send_key"].strip(), msg)) + print(u"已下发 pushbear 微信通知, 请查收") + except Exception as e: + print(u"pushbear 配置有误 {}".format(e)) + else: + pass + + +if __name__ == '__main__': + sendPushBear(1) \ No newline at end of file diff --git a/config/ticket_config.yaml b/config/ticket_config.yaml index 5738135..80d0509 100755 --- a/config/ticket_config.yaml +++ b/config/ticket_config.yaml @@ -103,6 +103,11 @@ email_conf: password: "" host: "smtp.qq.com" +# 是否开启 pushbear 微信提醒, 使用前需要前往 http://pushbear.ftqq.com 扫码绑定获取 send_key 并关注获得抢票结果通知的公众号 +pushbear_conf: + is_pushbear: False + send_key: "" + # 是否开启cdn查询,可以更快的检测票票 1为开启,2为关闭 is_cdn: 1 diff --git a/inter/QueryOrderWaitTime.py b/inter/QueryOrderWaitTime.py index 9dbc888..2e457ac 100644 --- a/inter/QueryOrderWaitTime.py +++ b/inter/QueryOrderWaitTime.py @@ -4,6 +4,7 @@ import time from config.TicketEnmu import ticket from config.emailConf import sendEmail +from config.pushbearConf import sendPushBear from myException.ticketIsExitsException import ticketIsExitsException from myException.ticketNumOutException import ticketNumOutException @@ -42,6 +43,8 @@ class queryOrderWaitTime: if data and 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): diff --git a/tkcode.png b/tkcode.png new file mode 100644 index 0000000..35a70ff Binary files /dev/null and b/tkcode.png differ