[Linux] Python 钉钉自定义机器人消息提醒
序
1昨天发现钉钉上还有机器人,弄了一个简单提醒
Code
1#!/usr/bin/python
2# -*- coding:utf-8 -*-
3#@Time : 2020/4/8 15:08
4#@Author: aeneag
5#@File : dingding.py
6
7import requests
8import json
9import time
10
11webhook = "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxx"
12header = {
13 "Content-Type": "application/json",
14 "Charset": "UTF-8"
15}
16def dingmessage():
17 tex1 = "不要忘记打卡@all"
18 tex2 = "不要忘记写日志@all"
19 while True:
20 time_now = time.strftime("%H:%M:%S", time.localtime())
21 mesTime(time_now,"07:55:10",tex1)
22 mesTime(time_now, "11:50:00", tex1)
23 mesTime(time_now, "13:29:00", tex1)
24 mesTime(time_now, "17:31:00", tex1)
25 mesTime(time_now, "19:30:00", tex2)
26 mesTime(time_now, "21:00:00", tex2)
27 time.sleep(0.5)
28
29def mesTime(time_now,texTime,tex):
30 if time_now == texTime:
31 message_json = json.dumps(mesInfo(tex))
32 requests.post(url=webhook, data=message_json, headers=header)
33
34def mesInfo(tex):
35 message1 ={
36 "msgtype": "text",
37 "text": {
38 "content": tex
39 },
40 "at": {
41 "isAtAll": True
42 }
43 }
44 return message1
45
46if __name__=="__main__":
47 dingmessage()
48
吾心信其可行,
则移山填海之难,
终有成功之日!
——孙文
则移山填海之难,
终有成功之日!
——孙文
评论
0 评论