1.代码简单
2.操作方便
3.不依赖jenkins
4.无前端显示窗口,防止误关
python+定时器BlockingScheduler+pythonw
众所周知,python与pythonw的最大区别就是pythonw后台运行
核心逻辑就是 cmd窗口运行pythonw ***.py实现了本地后台定时运行脚本
# -*- coding: utf-8 -*-
import json, requests, time, sys, datetime,random
sys.path.append("..")
import os, time, random, sys, datetime,csv
from apscheduler.schedulers.blocking import BlockingScheduler
true = True
false = False
null = None
def wbxhgz_dd():
print((time.strftime("%Y-%m-%dT%H:%M:%S.%S", time.localtime())))
oms_order = "100003"
oms_invoice = "100010"
pcm_pcm = "100018"
# _project_id = []
_sys_id = []
create_order_headers = {"Content-Type": "application/json", "Cookie": "sessionid=rjci81edx0ikkr2arthd2n9200smv8oi"}
_project_id = [oms_order,oms_invoice,pcm_pcm]
get_sys_id_url = 'http://mone.ninja.***china.net/***-api/testcase/view/get_interface_coverage'
for project_id in _project_id:
get_sys_id_data = {"current": 1, "pageSize": 100, "project_id":project_id}
get_sys_id_data = json.dumps(get_sys_id_data)
req = requests.post(url=get_sys_id_url, headers=create_order_headers, data=get_sys_id_data)
assert req.status_code == 200
res = json.loads(req.text)
if res['success'] != 1:
print(res)
for mu in res['data']:
if mu['coverage'] != "未查询到执行记录":
_sys_id.append(mu['sys_id'])
url = 'http://mone.ninja.***china.net/***-api/testcase/view/get_jacoco_report'
print(_sys_id)
for sys_id in _sys_id:
data = {"sys_id": sys_id, "env_name": "1004"}
create_order_data = json.dumps(data)
# print(create_order_data)
req = requests.post(url=url,headers=create_order_headers,data=create_order_data)
assert req.status_code == 200
res = json.loads(req.text)
print(data, res)
# 开始发送微企微消息
def qywx_send(key):
url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" + key
# 0731160e-0fde-4801-a73e-2bfd90**b259
param = {
"msgtype": "markdown",
"markdown": {"content": "阿里嘎多玛玛哈哈!"+str(_sys_id)
}
}
# print(param)
param = json.dumps(param)
storeheaders = {"Content-Type": "application/json"}
requests.post(url=url, data=param, headers=storeheaders)
# key = "0731160e-0fde-4801-a73e-2bfd90**b259"
key = ["14925278-6be3-46c2-b1d2-6b5e0f*****85"]
for mu in key:
# print(mu)
qywx_send(mu)
# 发送企微消息结束
sched = BlockingScheduler()
# @sched.scheduled_job('interval', seconds=3600)
sched.add_job(wbxhgz_dd, 'cron', day_of_week='mon-fri', hour=9, minute=50, end_date='2022-12-31')
sched.start()



