当前位置: 首页 > news >正文

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.lryc.cn/news/295476.html

相关文章:

  • 网站服务器中毒或是被入侵该怎么办?
  • Skywalking 学习之ByteBuddy 方法执行时间监控
  • idea vim配置
  • kafka排除zookeeper使用kraft的最新部署方案
  • SQL Server数据库日志查看若已满需要清理的三种解决方案
  • 人工智能 | 深度学习的进展
  • 玩转Java8新特性
  • EasyRecovery2024永久免费版电脑数据恢复软件下载
  • QQ音乐新版客户端的音乐无法解密?来看看解决方法!音乐解锁工具Web+批处理版本合集,附常见问题及解决方法!
  • 2023年12月CCF-GESP编程能力等级认证C++编程一级真题解析
  • 如何决定K8S Pod的剔除优先级
  • 【JavaScript】数据类型
  • JAVA:单例模式提高性能和安全性的优化技巧
  • 如何在 Ubuntu 上安装 ONLYOFFICE 文档 8.0
  • 什么是大模型
  • C#在既有数组中插入另一个数组:Array.Copy方法 vs 自定义插入方法
  • 上位机图像处理和嵌入式模块部署(linux开发板的选择)
  • 2024情人节送女朋友什么礼物?精准送礼看这个就对啦!男生必看!
  • 查询每张表占用磁盘空间大小(达梦数据库)
  • Vue3——创建一个应用
  • 深度学习系列56:使用whisper进行语音转文字
  • 【Web - 框架 - Vue】随笔 - 通过`CDN`的方式使用`VUE 2.0`和`Element UI`
  • 设计模式(行为型模式)备忘录模式
  • opencv案例实战:条码区域分割
  • 《MySQL》超详细笔记
  • 商用密码
  • css1文本属性
  • 在容器中使用buildah构建镜像
  • GPT4_VS_ChatGPT(from_nytimes)
  • 中兴R5300G4服务器查看服务器、主板序列号及硬盘RAID信息