!/usr/bin/env python3
coding:utf-8
import requests,json,sys,os,datetime
webhook="https://oapi.dingtalk.com/robot/send?access_token=88bddd19055305c4fba1f9698cabe891de279254ed6e331bc6a3005274478b71"
user=sys.argv[1]
text=sys.argv[3]
data={
"msgtype": "text",
"text": {
"content": text
},
"at": {
"atMobiles": [
user
],
"isAtAll": False
}
}
headers = {'Content-Type': 'application/json'}
x=requests.post(url=webhook,data=json.dumps(data),headers=headers)
if os.path.exists("/tmp/dingding.log"):
f=open("/tmp/dingding.log","a+")
else:
f=open("/tmp/dingding.log","w+")
f.write("\n"+"--"*30)
if x.json()["errcode"] == 0:
f.write("\n"+str(datetime.datetime.now()) + " " + str(user) + " " + "发送成功" + "\n" + str(text))
f.close()
else:
f.write("\n"+str(datetime.datetime.now()) + " " + str(user) + " " + "发送失败" + "\n" + str(text))
f.close()