钉钉机器人+Mac定时Launchctl

添加钉钉机器人

在这里插入图片描述
在这里插入图片描述

python 代码

# its_time_to_book_dinner.py
# coding:utf-8
import requests
dingtalk_url = "https://oapi.dingtalk.com/robot/send?" \
             "access_token=xxxxxxxxxxxxxxxxxx"
params = """
{
     "msgtype": "text",
     "text": {
         "content": "癫狗喊你美餐下单!"
     },
     "at": {
         "isAtAll": true
     }
}
"""
headers = {"Content-Type": "application/json"}
response = requests.post(dingtalk_url, data=params, headers=headers)
print response.content

Mac中的定时任务利器:launchctl

vim /path/to/run.sh
python /path/to/its_time_to_book_dinner.py
配置文件如下
vim ~/Library/LaunchAgents/com.dinner.order.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <!-- Label唯一的标识 -->
  <key>Label</key>
  <string>com.dinner.order.plist</string>
  <!-- 指定要运行的脚本 -->
  <key>ProgramArguments</key>
  <array>
    <string>/path/to/run.sh</string>
  </array>
  <!-- 指定要运行的时间 -->
  <key>StartCalendarInterval</key>
    <dict>

      <key>Minute</key>
      <integer>50</integer>

      <key>Hour</key>
      <integer>11</integer>

    </dict>
<!-- 标准输出文件 -->
<key>StandardOutPath</key>
<string>/path/to/run.log</string>
<!-- 标准错误输出文件,错误日志 -->
<key>StandardErrorPath</key>
<string>/path/to/run.err</string>
</dict>
</plist>
加载
launchctl load -w com.dinner.order.plist
修改配置文件重新加载
launchctl unload -w com.dinner.order.plist
launchctl load -w com.dinner.order.plist
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值