diff --git a/TickerConfig.py b/TickerConfig.py index a5d85a3..75b0d8e 100644 --- a/TickerConfig.py +++ b/TickerConfig.py @@ -92,6 +92,13 @@ PUSHBEAR_CONF = { "send_key": "" } +# 是否开启 server酱 微信提醒, 使用前需要前往 http://sc.ftqq.com/3.version 扫码绑定获取 SECRET 并关注获得抢票结果通知的公众号 +SERVER_CHAN_CONF = { + "is_server_chan": False, + "secret": "" +} + + # 是否开启cdn查询,可以更快的检测票票 1为开启,2为关闭 IS_CDN = 1 diff --git a/UnitTest/TestAll.py b/UnitTest/TestAll.py index 74ff210..05134f2 100644 --- a/UnitTest/TestAll.py +++ b/UnitTest/TestAll.py @@ -53,5 +53,15 @@ class testAll(unittest.TestCase): # :return: # """ + def testServerChan(self): + """ + 实测server酱是否可用 + :return: + """ + from config.serverchanConf import sendServerChan + + sendServerChan(u"server酱 微信通知测试一下") + + if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/config/serverchanConf.py b/config/serverchanConf.py new file mode 100644 index 0000000..f9078fd --- /dev/null +++ b/config/serverchanConf.py @@ -0,0 +1,36 @@ +# -*- coding: utf8 -*- +import TickerConfig +from config.urlConf import urls +from myUrllib.httpUtils import HTTPClient + +PUSH_SERVER_CHAN_PATH = "https://sc.ftqq.com" + + +def sendServerChan(msg): + """ + pushBear微信通知 + :param str: 通知内容 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() + sendServerChanUrls = urls.get("ServerChan") + sendServerChanUrls["req_url"] += f'{secret}.send' + + params = {"text": "易行购票成功通知", "desp": msg} + httpClint = HTTPClient(0) + sendServerChanRsp = httpClint.send(sendServerChanUrls, params=params) + if sendServerChanRsp.get("errno") == 0: + print(u"已下发 Server酱 微信通知, 请查收") + else: + print(sendServerChanRsp) + except Exception as e: + print(u"Server酱 配置有误 {}".format(e)) + + +if __name__ == "__main__": + sendServerChan(1) diff --git a/config/urlConf.py b/config/urlConf.py index 8ef5e74..31ff607 100755 --- a/config/urlConf.py +++ b/config/urlConf.py @@ -408,6 +408,19 @@ urls = { "is_logger": False, "is_json": True, }, + "ServerChan": { # Server酱 push通知 + "req_url": "/", + "req_type": "get", + "Referer": "", + "Content-Type": 1, + "Host": "sc.ftqq.com", + "re_try": 10, + "re_time": 0.01, + "s_time": 0.1, + "is_logger": True, + "is_json": True, + }, + "cdn_host": { "req_url": "http://ping.chinaz.com/kyfw.12306.cn", "req_type": "post" diff --git a/run.py b/run.py index 4e42f22..dea77c6 100755 --- a/run.py +++ b/run.py @@ -1,6 +1,7 @@ # -*- coding=utf-8 -*- from config.emailConf import sendEmail from config.pushbearConf import sendPushBear +from config.serverchanConf import sendServerChan from init import select_ticket_info @@ -16,7 +17,11 @@ def PushbearConf(): sendPushBear("订票小助手测试一下") +def PushServerChan(): + sendServerChan("订票小助手测试一下") + + if __name__ == '__main__': run() # Email() - # PushbearConf() \ No newline at end of file + # PushbearConf()