Merge pull request #328 from jasonqiao36/add-ServerChan

Add server chan
pull/334/head
wenxianping 2019-09-09 16:23:29 +08:00 committed by GitHub
commit 823cddaeaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 1 deletions

View File

@ -87,6 +87,13 @@ PUSHBEAR_CONF = {
"send_key": "" "send_key": ""
} }
# 是否开启 server酱 微信提醒, 使用前需要前往 http://sc.ftqq.com/3.version 扫码绑定获取 SECRET 并关注获得抢票结果通知的公众号
SERVER_CHAN_CONF = {
"is_server_chan": False,
"secret": ""
}
# 是否开启cdn查询可以更快的检测票票 1为开启2为关闭 # 是否开启cdn查询可以更快的检测票票 1为开启2为关闭
IS_CDN = 1 IS_CDN = 1

View File

@ -7,6 +7,7 @@ import requests
from agency.agency_tools import proxy from agency.agency_tools import proxy
from config.emailConf import sendEmail from config.emailConf import sendEmail
from config.pushbearConf import sendPushBear from config.pushbearConf import sendPushBear
from config.serverchanConf import sendServerChan
def _set_header_default(): def _set_header_default():
@ -53,5 +54,13 @@ class testAll(unittest.TestCase):
# :return: # :return:
# """ # """
def testServerChan(self):
"""
实测server酱是否可用
:return:
"""
sendServerChan(u"server酱 微信通知测试一下")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

36
config/serverchanConf.py Normal file
View File

@ -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)

View File

@ -408,6 +408,19 @@ urls = {
"is_logger": False, "is_logger": False,
"is_json": True, "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": { "cdn_host": {
"req_url": "http://ping.chinaz.com/kyfw.12306.cn", "req_url": "http://ping.chinaz.com/kyfw.12306.cn",
"req_type": "post" "req_type": "post"

View File

@ -9,6 +9,7 @@ import TickerConfig
from config.TicketEnmu import ticket from config.TicketEnmu import ticket
from config.emailConf import sendEmail from config.emailConf import sendEmail
from config.pushbearConf import sendPushBear from config.pushbearConf import sendPushBear
from config.serverchanConf import sendServerChan
from config.urlConf import urls from config.urlConf import urls
from inter.ConfirmSingleForQueue import confirmSingleForQueue from inter.ConfirmSingleForQueue import confirmSingleForQueue
from myException.ticketIsExitsException import ticketIsExitsException from myException.ticketIsExitsException import ticketIsExitsException
@ -130,6 +131,7 @@ class queryQueueByAfterNate:
else: else:
sendEmail(ticket.WAIT_ORDER_SUCCESS) sendEmail(ticket.WAIT_ORDER_SUCCESS)
sendPushBear(ticket.WAIT_ORDER_SUCCESS) sendPushBear(ticket.WAIT_ORDER_SUCCESS)
sendServerChan(ticket.WAIT_ORDER_SUCCESS)
raise ticketIsExitsException(ticket.WAIT_AFTER_NATE_SUCCESS) raise ticketIsExitsException(ticket.WAIT_AFTER_NATE_SUCCESS)

View File

@ -5,6 +5,7 @@ import time
from config.TicketEnmu import ticket from config.TicketEnmu import ticket
from config.emailConf import sendEmail from config.emailConf import sendEmail
from config.pushbearConf import sendPushBear from config.pushbearConf import sendPushBear
from config.serverchanConf import sendServerChan
from myException.ticketIsExitsException import ticketIsExitsException from myException.ticketIsExitsException import ticketIsExitsException
from myException.ticketNumOutException import ticketNumOutException from myException.ticketNumOutException import ticketNumOutException
@ -45,6 +46,8 @@ class queryOrderWaitTime:
data.get("orderId", ""))) data.get("orderId", "")))
sendPushBear(ticket.WAIT_ORDER_SUCCESS.format( sendPushBear(ticket.WAIT_ORDER_SUCCESS.format(
data.get("orderId", ""))) data.get("orderId", "")))
sendServerChan(ticket.WAIT_ORDER_SUCCESS.format(
data.get("orderId", "")))
raise ticketIsExitsException(ticket.WAIT_ORDER_SUCCESS.format( raise ticketIsExitsException(ticket.WAIT_ORDER_SUCCESS.format(
data.get("orderId"))) data.get("orderId")))
elif data.get("msg", False): elif data.get("msg", False):

7
run.py
View File

@ -1,6 +1,7 @@
# -*- coding=utf-8 -*- # -*- coding=utf-8 -*-
from config.emailConf import sendEmail from config.emailConf import sendEmail
from config.pushbearConf import sendPushBear from config.pushbearConf import sendPushBear
from config.serverchanConf import sendServerChan
from init import select_ticket_info from init import select_ticket_info
@ -16,7 +17,11 @@ def PushbearConf():
sendPushBear("订票小助手测试一下") sendPushBear("订票小助手测试一下")
def PushServerChan():
sendServerChan("订票小助手测试一下")
if __name__ == '__main__': if __name__ == '__main__':
run() run()
# Email() # Email()
# PushbearConf() # PushbearConf()