Skip to content

Latest commit

 

History

History
83 lines (78 loc) · 3.05 KB

通知工具.md

File metadata and controls

83 lines (78 loc) · 3.05 KB

seatools.notices 通知工具

  1. seatools.notices.SmtpEmailNotice - class: 邮件通知工具, 示例
from seatools.notices import SmtpEmailNotice
from seatools.builders import HtmlBuilder

# 初始化邮件提醒工具
notice = SmtpEmailNotice(smtp_server='xxx',
                         smtp_port=465,
                         from_email='',
                         from_password='',
                         from_name='')
# 发送邮件
notice.send_email('测试标题',
                  HtmlBuilder(auto_add_html_tag=True).h1('正文1号').p('正文换行').a('正文标签',
                                                                                    'https://www.baidu.com'),
                  to_emails=['[email protected]'],
                  to_cc_mails=['[email protected]'],  # 抄送人
                  attachments=['xxx.txt', 'path_to_file'],  # 附件路径
                  )
  1. seatools.notices.FeishuRobotNotice - class: 飞书机器人通知工具
  2. seatools.notices.FeishuRobotTextMsg - class: 飞书机器人普通消息类型
  3. seatools.notices.FeishuRobotPostMsg - class: 飞书机器人富文本消息类型
  4. seatools.notices.FeishuRobotCardMsg - class: 飞书机器人卡片消息类型 (不推荐直接使用, 推荐使用seatools.notices.FeishuRobotCardMsgTemplate卡片消息模板生成该实例)

示例:

from seatools.notices import FeishuRobotNotice, FeishuRobotTextMsg, FeishuRobotPostMsg,
    FeishuRobotCardMsg, FeishuRobotCardMsgTemplate

notice = FeishuRobotNotice(webhook='xxx')
# 普通文本消息
notice.send_msg(FeishuRobotTextMsg(text='测试消息'))
# 富文本消息
notice.send_msg(FeishuRobotPostMsg(title='富文本消息标题',
                                   content=FeishuRobotPostMsg.content_builder(
                                   ).add_text('富文本消息').add_a('富文本链接',
                                                                  href='https://www.baidu.com').add_newline().add.build()))
# 卡片消息
# 方式1: 使用卡片消息模板消息生成卡片消息发送(推荐)
card_template = FeishuRobotCardMsgTemplate(elements=[
    {
        "tag": "div",
        "text": {
            "content": "{{content}}!xxx",
            "tag": "lark_md"
        }
    }
], config={
    "wide_screen_mode": True
}, header={
    "template": "blue",
    "title": {
        "content": "{{title}}",
        "tag": "plain_text"
    }
})
# 使用卡片模板card_template.gen_msg方法生成卡片消息并发送
notice.send_msg(card_template.gen_msg(elements_map={'content': '测试正文'},
                                      header_map={'title': '测试标题'}))
# 方式2: 直接发送卡片消息
notice.send_msg(FeishuRobotCardMsg(elements=[
    {
        "tag": "div",
        "text": {
            "content": "测试正文",
            "tag": "lark_md"
        }
    }
], config={
    "wide_screen_mode": True
}, header={
    "template": "blue",
    "title": {
        "content": "测试标题",
        "tag": "plain_text"
    }
}))

更多示例见: tests.test_notices.py文件