import datetime

import requests

from unitls.LogerinTxt import app_logger
from .flightDB import flightDB


def dingdinginfoget(database:flightDB):
    try:
        infos={}
        try:
            resfwq = requests.get(url="http://124.223.185.200:4567/get_deal_info/", timeout=10)  # 自己服务器
            if resfwq.json() != "":
                infos = resfwq.json()
        except Exception as e:
            app_logger.log_error(e)
            pass
        #print("infos",infos)
        if infos !={}:
            now = datetime.datetime.now()
            for i in infos.keys():
                info=str(infos[i]["info"].split("信息上报")[0])+str(now.strftime("%Y-%m-%d %H:%M:%S"))+"上报信息，鼠标停留查看详情"
                newdic = {"航班编号": "%s" % i, "警告信息": "%s"%info, "信息状态": "", "提示信息": "",
                          "产生时间": "%s" % now, "处理人": "", "处理时间": "", "变更字段": "", "显示对象": "", "提示内容": "%s"%infos[i]["info"]}
                database.lazyInsertData('logs', newdic)
            database.FunctionCommit()
    except Exception as e:
        app_logger.log_error(e)
        database.FunctionCommit()