使用钉钉机器人做一个监控

生成access token

发送消息

def send_message(text):
    send_url = 'https://oapi.dingtalk.com/robot/send?access_token=xxx'

    headers = {
        'Content-Type': 'application/json',
        "Charset": "UTF-8"
    }
    data = {
        "msgtype": "markdown",
        "markdown": {
            "title": "python",
            "text": text
        },
        "at": {
            # "atMobiles": [
            #     "18788888888"
            # ],
            "isAtAll": True
        }
    }
    resp = requests.post(url=send_url, headers=headers, json=data)
    print(resp.json())


if __name__ == '__main__':
    text = """
    #### 深圳天气 
    > 20度,西北风1级,空气良89,相对温度73%
    > ![screenshot](https://img95.699pic.com/photo/50055/5642.jpg_wh860.jpg)
    > ###### 10点21分发布 [天气](https://www.baidu.com)
    """
    send_message(text)

结果

posted @ 2020-12-09 18:27  rm-rf*  阅读(649)  评论(0编辑  收藏  举报