import datetime

from unitls.LogerinTxt import app_logger
from .flightDB import flightDB


def UpdateNoteItem(fdb:flightDB,text,name):
    try:
        nowDay = datetime.date.today().strftime("%Y%m%d")
        nowDay_1 = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y%m%d")
        a_str = nowDay + " 09:00:00"
        b_str = nowDay + " 20:30:00"
        a = datetime.datetime.strptime(a_str, "%Y%m%d %H:%M:%S")
        b = datetime.datetime.strptime(b_str, "%Y%m%d %H:%M:%S")
        nowtime = datetime.datetime.now()
        if a < nowtime < b:
            bcdate = nowDay
        elif b <= nowtime:
            bcdate = nowDay
        else:
            bcdate = nowDay_1
        if text != "清空项目12345678987654321":
            newdic={'备注':"'%s'"%text}
        else:
            newdic={'备注':"''"}

        fdb.upDateItem("pglist{}".format(bcdate),newdic,"姓名='%s'"%name)
    except Exception as e:
        app_logger.log_error(e)