飞书机器人定时通知第二天值班人

定时脚本

30 18 * * * /usr/bin/python3.6 /home/work/脚本.py > /home/work/log.log 2>&1

代码:

# encoding:utf-8
import json
import requests
import datetime

# 群组中的人员列表
group_members = ['人员1|1234567','人员2|2345678','人员3|3456789']  # 以列表形式提供群组中的人员名单

def get_notification_index(date,total_members):
  ordinal_day = date.toordinal()  # 获取日期的自 0001-01-01 开始的天数
  return ordinal_day%total_members

try:
  # 获取当前日期
  date1 = datetime.datetime.now().date()
  date2 = date1 + datetime.timedelta(days=1)

  total_members = len(group_members)
  notification_index_2 = get_notification_index(date2,total_members)
  notification_person_2 = group_members[notification_index_2].split("|")[0]
  notification_phone_2 = group_members[notification_index_2].split("|")[1]

except ValueError as e:
  print("日期转换失败:", e)

notes="请注意手机不要静音,辛苦了!"

def send():
    #url = "飞书地址"
    headers = {
        'Content-Type': 'application/json'
    }
    card ={
          "header": {
            "template": "purple",
            "title": {
              "content": f"明日 {notification_person_2} 值班",
              "tag": "plain_text"
            }
          },
          "elements": [
            {
              "tag": "column_set",
              "flex_mode": "none",
              "background_style": "default",
              "columns": [
                {
                  "tag": "column",
                  "width": "weighted",
                  "weight": 1,
                  "vertical_align": "top",
                  "elements": [
                    {
                      "content": f"值 班 员:{notification_person_2}",
                      "tag": "markdown"
                    }
                  ]
                }
              ]
            },
            {
              "tag": "column_set",
              "flex_mode": "none",
              "background_style": "default",
              "columns": [
                {
                  "tag": "column",
                  "width": "weighted",
                  "weight": 1,
                  "vertical_align": "top",
                  "elements": [
                    {
                      "content": f"值班电话: {notification_phone_2}",
                      "tag": "markdown"
                    }
                  ]
                }
              ]
            },
            {
              "tag": "column_set",
              "flex_mode": "none",
              "background_style": "default",
              "columns": [
                {
                  "tag": "column",
                  "width": "weighted",
                  "weight": 1,
                  "vertical_align": "top",
                  "elements": [
                    {
                      "content": f"值班时间: {date1} 21:30 ~ {date2} 09:30",
                      "tag": "markdown"
                    }
                  ]
                }
              ]
            },
            {
              "tag": "column_set",
              "flex_mode": "none",
              "background_style": "default",
              "columns": [
                {
                  "tag": "column",
                  "width": "weighted",
                  "weight": 1,
                  "vertical_align": "top",
                  "elements": [
                    {
                      "tag": "markdown",
                      "content": f"备    注:{notes}"
                    }
                  ]
                }
              ]
            }
          ]
    }
    body = json.dumps({"msg_type":"interactive","card":card})
    response = requests.post(url=url,data=body,headers=headers)
    print(response.headers['X-Tt-Logid']) # for debug or oncall
    print(response.content) # Print Response
if __name__ == '__main__':
  send()
  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_49457994

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值