飞书卡片发布多个定时任务案例python

# -*- coding: utf-8 -*-
"""
Created on Mon Jun  5 11:18:45 2023

@author: Administrator
"""

import requests
import json

from apscheduler.schedulers.blocking import BlockingScheduler
import datetime
#下午三点的下午茶
def job():
    #飞书机器人发送

    url = 'https://open.feishu.cn/open-apis/bot/v2/hook/7ae02b0f-63a5-4c13-af99-9f6fe6f05c46' 

    method = 'post'
    headers = {
        'Content-Type': 'application/json'
    }

    json = {
        "msg_type": "interactive",
        "card":
            {
            "config": {
    "wide_screen_mode": True
    },
    "elements": [
    {
    "tag": "div",
    "text": {
    "content": "今天工作辛苦了,三点的下午茶记得奖励自己哦!",
    "tag": "lark_md"
    }
    },
    {
    "actions": [
    {
        "tag": "button",
        "text": {
        "content": "立刻去",
        "tag": "plain_text"
        },
        "type": "primary",
        "multi_url": {
        "url": "https://open.feishu.cn/",
        "android_url": "",
        "ios_url": "",
        "pc_url": ""
        }
    },
    {
        "tag": "button",
        "text": {
        "content": "暂时不去",
        "tag": "plain_text"
        },
        "type": "default",
        "multi_url": {
        "url": "https://open.feishu.cn/",
        "android_url": "",
        "ios_url": "",
        "pc_url": ""
        }
    }
    ],
    "tag": "action"
    }
    ],
    "header": {
    "template": "turquoise",
    "title": {
    "content": "📚放松一下",
    "tag": "plain_text"
    }
    }
            }
    }

    requests.request(method=method, url=url, headers=headers, json=json)
#中午的午饭
def job1():
    #飞书机器人发送

    url1 = 'https://open.feishu.cn/open-apis/bot/v2/hook/7ae02b0f-63a5-4c13-af99-9f6fe6f05c46' 

    method = 'post'
    headers = {
        'Content-Type': 'application/json'
    }

    json = {
        "msg_type": "interactive",
        "card":
            {
            "config": {
    "wide_screen_mode": True
    },
    "elements": [
    {
    "tag": "div",
    "text": {
    "content": "今天工作辛苦了,别忘了吃午饭哦!",
    "tag": "lark_md"
    }
    },
    {
    "actions": [
    {
        "tag": "button",
        "text": {
        "content": "立刻去",
        "tag": "plain_text"
        },
        "type": "primary",
        "multi_url": {
        "url": "https://open.feishu.cn/",
        "android_url": "",
        "ios_url": "",
        "pc_url": ""
        }
    },
    {
        "tag": "button",
        "text": {
        "content": "暂时不去",
        "tag": "plain_text"
        },
        "type": "default",
        "multi_url": {
        "url": "https://open.feishu.cn/",
        "android_url": "",
        "ios_url": "",
        "pc_url": ""
        }
    }
    ],
    "tag": "action"
    }
    ],
    "header": {
    "template": "turquoise",
    "title": {
    "content": "📚放松一下",
    "tag": "plain_text"
    }
    }
            }
    }

    requests.request(method=method, url1=url1, headers=headers, json=json)
#下午五点五十五的晚饭    
def job2():
    #飞书机器人发送

    url2 = 'https://open.feishu.cn/open-apis/bot/v2/hook/7ae02b0f-63a5-4c13-af99-9f6fe6f05c46' 

    method = 'post'
    headers = {
        'Content-Type': 'application/json'
    }

    json = {
        "msg_type": "interactive",
        "card":
            {
            "config": {
    "wide_screen_mode": True
    },
    "elements": [
    {
    "tag": "div",
    "text": {
    "content": "今天工作辛苦了,晚饭别忘了哦!",
    "tag": "lark_md"
    }
    },
    {
    "actions": [
    {
        "tag": "button",
        "text": {
        "content": "立刻去",
        "tag": "plain_text"
        },
        "type": "primary",
        "multi_url": {
        "url": "https://open.feishu.cn/",
        "android_url": "",
        "ios_url": "",
        "pc_url": ""
        }
    },
    {
        "tag": "button",
        "text": {
        "content": "暂时不去",
        "tag": "plain_text"
        },
        "type": "default",
        "multi_url": {
        "url": "https://open.feishu.cn/",
        "android_url": "",
        "ios_url": "",
        "pc_url": ""
        }
    }
    ],
    "tag": "action"
    }
    ],
    "header": {
    "template": "turquoise",
    "title": {
    "content": "📚放松一下",
    "tag": "plain_text"
    }
    }
            }
    }

    requests.request(method=method, url2=url2, headers=headers, json=json)
#早上打卡    
def job3():
    #飞书机器人发送

    url3 = 'https://open.feishu.cn/open-apis/bot/v2/hook/7ae02b0f-63a5-4c13-af99-9f6fe6f05c46' 

    method = 'post'
    headers = {
        'Content-Type': 'application/json'
    }

    json = {
        "msg_type": "interactive",
        "card":
            {
            "config": {
    "wide_screen_mode": True
    },
    "elements": [
    {
    "tag": "div",
    "text": {
    "content": "又是崭新的一天,别忘了打卡!",
    "tag": "lark_md"
    }
    },
    {
    "actions": [
    {
        "tag": "button",
        "text": {
        "content": "马上打",
        "tag": "plain_text"
        },
        "type": "primary",
        "multi_url": {
        "url": "https://open.feishu.cn/",
        "android_url": "",
        "ios_url": "",
        "pc_url": ""
        }
    },
    {
        "tag": "button",
        "text": {
        "content": "马上到",
        "tag": "plain_text"
        },
        "type": "default",
        "multi_url": {
        "url": "https://open.feishu.cn/",
        "android_url": "",
        "ios_url": "",
        "pc_url": ""
        }
    }
    ],
    "tag": "action"
    }
    ],
    "header": {
    "template": "turquoise",
    "title": {
    "content": "📚记得打卡",
    "tag": "plain_text"
    }
    }
            }
    }

    requests.request(method=method, url2=url2, headers=headers, json=json)
#晚上打卡    
def job4():
    #飞书机器人发送

    url2 = 'https://open.feishu.cn/open-apis/bot/v2/hook/7ae02b0f-63a5-4c13-af99-9f6fe6f05c46' 

    method = 'post'
    headers = {
        'Content-Type': 'application/json'
    }

    json = {
        "msg_type": "interactive",
        "card":
            {
            "config": {
    "wide_screen_mode": True
    },
    "elements": [
    {
    "tag": "div",
    "text": {
    "content": "今天工作辛苦了,别忘了打卡!",
    "tag": "lark_md"
    }
    },
    {
    "actions": [
    {
        "tag": "button",
        "text": {
        "content": "立刻打",
        "tag": "plain_text"
        },
        "type": "primary",
        "multi_url": {
        "url": "https://open.feishu.cn/",
        "android_url": "",
        "ios_url": "",
        "pc_url": ""
        }
    },
    {
        "tag": "button",
        "text": {
        "content": "等会儿打",
        "tag": "plain_text"
        },
        "type": "default",
        "multi_url": {
        "url": "https://open.feishu.cn/",
        "android_url": "",
        "ios_url": "",
        "pc_url": ""
        }
    }
    ],
    "tag": "action"
    }
    ],
    "header": {
    "template": "turquoise",
    "title": {
    "content": "📚记得打卡",
    "tag": "plain_text"
    }
    }
            }
    }

    requests.request(method=method, url2=url2, headers=headers, json=json)
# 创建一个调度器
scheduler = BlockingScheduler()

# 添加任务,每天早上 10 点执行一次
#scheduler.add_job(job, 'cron', hour=10)
scheduler.add_job(job, 'cron', hour=14, minute=58)
# 开始调度任务
scheduler.start()

# 创建一个调度器
scheduler1 = BlockingScheduler()


#scheduler.add_job(job, 'cron', hour=10)
scheduler1.add_job(job1, 'cron', hour=11, minute=30)
# 开始调度任务
scheduler1.start()

# 创建一个调度器
scheduler2 = BlockingScheduler()


#scheduler.add_job(job, 'cron', hour=10)
scheduler2.add_job(job2, 'cron', hour=17, minute=53)
# 开始调度任务
scheduler2.start()

# 创建一个调度器
scheduler3 = BlockingScheduler()


#scheduler.add_job(job, 'cron', hour=10)
scheduler3.add_job(job3, 'cron', hour=8, minute=50)
# 开始调度任务
scheduler3.start()

# 创建一个调度器
scheduler4 = BlockingScheduler()


#scheduler.add_job(job, 'cron', hour=10)
scheduler4.add_job(job4, 'cron', hour=18, minute=5)
# 开始调度任务
scheduler4.start()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值