美文网首页
钉钉机器人+Mac定时Launchctl

钉钉机器人+Mac定时Launchctl

作者: 阿武z | 来源:发表于2018-07-24 11:37 被阅读256次

添加钉钉机器人

钉钉客户端添加机器人 机器人编辑

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

相关文章

网友评论

      本文标题:钉钉机器人+Mac定时Launchctl

      本文链接:https://www.haomeiwen.com/subject/kweemftx.html