工具使用|钉钉机器人+Mac定时Launchctl

添加钉钉机器人
【工具使用|钉钉机器人+Mac定时Launchctl】工具使用|钉钉机器人+Mac定时Launchctl
文章图片

工具使用|钉钉机器人+Mac定时Launchctl
文章图片

  • webhook地址是 post请求的url
  • 机器人开发文档
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=https://www.it610.com/article/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 Label >com.dinner.order.plistProgramArguments >/path/to/run.sh StartCalendarInterval Minute 50Hour 11StandardOutPath >/path/to/run.logStandardErrorPath >/path/to/run.err

加载
launchctl load -w com.dinner.order.plist

修改配置文件重新加载
launchctl unload -w com.dinner.order.plist launchctl load -w com.dinner.order.plist

    推荐阅读