# coding: utf-8
import json
import requests

def dingding_robot(data):
    # 机器人的webhooK 获取地址参考：https://open-doc.dingtalk.com/microapp/serverapi2/qf2nxq
    webhook = "https://oapi.dingtalk.com/robot/send?access_token=5131b887f6b022150f903e9d690e08c0d481fba844545034aaf48906ee026fa0"
    headers = {'content-type': 'application/json'} # 请求头
    r = requests.post(webhook, headers=headers, data=json.dumps(data))
    r.encoding = 'utf-8'
    return (r.text)


if __name__ == "__main__":

    import linecache
    str = ""
    for i in range(36,64):
        s=linecache.getline('/srv/apps/ffm-baseline/eda/recommended_indexs/hypothesis_test.txt', i).strip("\n").split(",")
        if s[0] != "":
            str += s[0]+"\n"
    str +="【很重要】如下有变更，请提醒相关的人:1.推荐模型变更优化，影响CTR或者CVR(王志伟)；2.任何涉及到数据库schame变更(王志伟)"
    print(str)

    # 请求参数 可以写入配置文件中

    data = {
        "msgtype": "text",
        "text": {
            "content": str,
            "title": "自定义机器人"

            # "picUrl": "",
            # "messageUrl": "https://www.baidu.com/"
        },
        "at": {
            "atMobiles":["17310453926"]
        }
    }
    res = dingding_robot(data)
    print(res) # 打印请求结果