Skip to content

Commit

Permalink
添加测试用例, 完善pushbear代码
Browse files Browse the repository at this point in the history
  • Loading branch information
stormeyes committed Jan 10, 2019
1 parent bc88a9e commit 1c5ba95
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions UnitTest/TestAll.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from agency.agency_tools import proxy
from config.emailConf import sendEmail
from config.pushbearConf import sendPushBear


def _set_header_default():
Expand Down Expand Up @@ -38,6 +39,13 @@ def testEmail(self):
:return:
"""
sendEmail("订票小助手测试一下")

def testPushbear(self):
"""
实测pushbear是否可用
:return:
"""
sendPushBear("pushbear 微信通知测试一下")

# def testConfig(self):
# """
Expand Down
26 changes: 26 additions & 0 deletions config/pushbearConf.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions config/ticket_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions inter/QueryOrderWaitTime.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

Expand Down Expand Up @@ -42,6 +43,8 @@ def sendQueryOrderWaitTime(self):
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):
Expand Down
Binary file added tkcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1c5ba95

Please sign in to comment.