python实现飞书群机器人消息通知(消息卡片)

python实现飞书群机器人消息通知

直接上代码

"""
飞书群机器人发送通知
"""
import time
import urllib3
import datetimeurllib3.disable_warnings()class FlybookRobotAlert():def __init__(self):self.webhook = webhook_urlself.headers = {Content-Type: application/json; charset=UTF-8}def post_to_robot(self, post_data):'''给飞书机器人发送请求:param data::return:'''try:resp = requests.request(method="POST", url=self.webhook, data=post_data, headers=self.headers).json()if resp.get("StatusCode") == 0 and resp.get("msg") == "success":Logger.info(f"飞书通知发送成功,msg={resp}")else:Logger.warning(f"飞书通知发送失败,{resp}")except Exception as e:Logger.warning("飞书通知发送异常")Logger.warning(e)passdef send_message(self, proj_name, total, passed, failed, skipped, adress="https://www.example.com"):# 飞书通知标题robot_headers = "自动化报告"# 自定义飞书通知内容robot_content = "ddd!自动化执行情况反馈,请相关测试童鞋注意!并及时跟进!"execute_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")field_list = [{"is_short": False,"text": {"tag": "lark_md","content": f"**用例执行完毕时间**:<font color=\"green\">{{}}</font>\n".format(execute_time)}},{"is_short": False,"text": {"tag": "lark_md","content": f"**项目名称**:<font color=\"green\">{{}}</font>\n".format(proj_name)}},{"is_short": False,"text": {"tag": "lark_md","content": f"**用例总数**:<font color=\"green\">{{}}</font>\n".format(total)}},{"is_short": False,"text": {"tag": "lark_md","content": f"**通过用例数**:<font color=\"green\">{{}}</font>\n".format(passed)}},{"is_short": False,"text": {"tag": "lark_md","content": f"**失败用例数**:<font color=\"green\">{{}}</font>\n".format(failed)}},{"is_short": False,"text": {"tag": "lark_md","content": f"**跳过用例数**:<font color=\"green\">{{}}</font> \n".format(skipped)}}]card = json.dumps({"config": {"wide_screen_mode": True},"elements": [{"tag": "div","text": {"content": robot_content,"tag": "lark_md"}},{"tag": "div","fields": field_list},{"actions": [{"tag": "button","text": {"tag": "plain_text","content": "allure报告,请点击查看"},"url": adress,"type": "primary"}],"tag": "action"}],"header": {"template": "red","title": {"content": robot_headers,"tag": "plain_text"}}})msg_body = json.dumps({"msg_type": "interactive", "card": card})self.post_to_robot(data=msg_body)# {'StatusCode': 0, 'StatusMessage': 'success', 'code': 0, 'data': {}, 'msg': 'success'}returnif __name__ == '__main__':a = FlybookRobotAlert()a.send_message('你的项目名称GoGoGo', 4, 4, 0, 0)

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/459751.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Kafka 入门介绍

目录 一. 前言 二. 使用场景 三. 分布式的流平台 四. Kafka 的基本术语 4.1. 主题和日志 &#xff08;Topic 和 Log&#xff09; 4.2. 分布式&#xff08;Distribution&#xff09; 4.3. 异地数据同步技术&#xff08;Geo-Replication&#xff09; 4.4. 生产者&#xf…

cpp11新特性之智能指针(下):深入理解现代cpp中的智能指针shared_ptr、unique_ptr 以及 weak_ptr

目录 写在前面 unique_ptr shared_ptr weak_ptr 智能指针的使用陷阱 致谢 写在前面 上一篇文章同大家深入探讨了auto_ptr。今天给大家带来的是对于 shared_ptr、unique_ptr 以及 weak_ptr 的深入理解&#xff0c;通过测试案例和源码剖析对这三种重要的智能指针的使用方法&…

springboot164党员教育和管理系统

简介 【毕设源码推荐 javaweb 项目】基于springbootvue 的 适用于计算机类毕业设计&#xff0c;课程设计参考与学习用途。仅供学习参考&#xff0c; 不得用于商业或者非法用途&#xff0c;否则&#xff0c;一切后果请用户自负。 看运行截图看 第五章 第四章 获取资料方式 **项…

npm 上传一个自己的应用(4) 更新自己上传到NPM中的工具版本 并进行内容修改

前面 npm 上传一个自己的应用(2) 创建一个JavaScript函数 并发布到NPM 我们讲了将自己写的一个函数发送到npm上 那么 如果我们想到更好的方案 希望对这个方法进行修改呢&#xff1f; 比如 我们这里加一个方法 首先 我们还是要登录npm npm login然后 根据要求填写 Username 用…

以“防方视角”观JS文件信息泄露

为方便您的阅读&#xff0c;可点击下方蓝色字体&#xff0c;进行跳转↓↓↓ 01 案例概述02 攻击路径03 防方思路 01 案例概述 这篇文章来自微信公众号“黑白之道”&#xff0c;记录的某师傅从js文件泄露接口信息&#xff0c;未授权获取大量敏感信息以及通过逻辑漏洞登录管理员账…

Appium使用初体验之参数配置,简单能够运行起来

一、服务器配置 Appium Server配置与Appium Server GUI&#xff08;可视化客户端&#xff09;中的配置对应&#xff0c;尤其是二者如果不在同一台机器上&#xff0c;那么就需要配置Appium Server GUI所在机器的IP&#xff08;Appium Server GUI的HOST也需要配置本机IP&#xf…

C#,栅栏油漆算法(Painting Fence Algorithm)的源代码

1 刷油漆问题 给定一个有n根柱子和k种颜色的围栏&#xff0c;找出油漆围栏的方法&#xff0c;使最多两个相邻的柱子具有相同的颜色。因为答案可以是大的&#xff0c;所以返回10^97的模。 计算结果&#xff1a; 2 栅栏油漆算法的源程序 using System; namespace Legalsoft.Tr…

详细分析python中的 async 和 await(附Demo)

目录 前言1. 基本知识2. Demo2.1 Demo1&#xff08;同步&#xff09;2.2 Demo2&#xff08;错误&#xff09;2.3 Demo3&#xff08;不正确的异步&#xff09;2.4 Demo4&#xff08;正确异步&#xff09; 3. 完整版4. 拓展4.1 asyncio.create_task(coroutine)4.2 asyncio.gather…

PAT-Apat甲级题1009(python和c++实现)

PTA | 1009 Product of Polynomials 1009 Product of Polynomials 作者 CHEN, Yue 单位 浙江大学 This time, you are supposed to find AB where A and B are two polynomials. Input Specification: Each input file contains one test case. Each case occupies 2 lin…

【社交电商】带直播电商功能,可以DIY前端,可以H5和小程序一般商城常用功能齐全

第一次接触这个系统&#xff0c;感觉和微擎有点像。也是一个主体&#xff0c;也很多插件的那种。 测试了下。安装成功了&#xff0c;站长亲测没有问题&#xff0c;一切都挺完善的&#xff0c;不过系统比较庞大&#xff0c;可能新手熟悉起来要一定的过程。 站长整理了一份简要…

3060ti显卡+cuda12.1+win10编译安装生成fastdeploy的c++与python库

在cuda12中,调用官方发布的fastdeploy会出现报错,故此自行编译fastdeploy库。 官网编译教程:https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md 可选编译选项 编译选项 无论是在何平台编译,编译时仅根据需求修改如下选项,勿…

使用pygame生成红包封面

import pygame import sys# 初始化pygame pygame.init()# 设置红包封面尺寸 size width, height 640, 960 screen_color (255, 0, 0) # 红色背景# 创建窗口 screen pygame.display.set_mode(size) pygame.display.set_caption(红包封面)# 加载龙形图片 dragon_image pygam…