import subprocess
from datetime import timedelta, date


def IsFileContentRight(url):
    f = open(url, "r", encoding="utf-8")  # 从文件中读取内容
    str1=f.read()
    import re
    if (re.search("，",str1)!=None or re.search("：",str1)!=None):
        return  False
    else:
        f.close()
    f = open(url, "r", encoding="utf-8")  # 从文件中读取内容
    mylist1 = f.readlines()

    x = 0
    j = 0
    count=0
    for i in mylist1:
        if (re.match("子任务数:", i) != None):
            print("找到了")
            j = i[5:6]
            print('子任务数', j)
            break
    for i in mylist1:
        if (re.match("任务", i) != None):
            print('找到了%s个任务' % x)
            x = x + 1
            print("真实子任务个数", x)
    for i in mylist1:
        if (re.match("实际工时", i) != None):
            count=i.count(",")
            count = int(count) + 1
            # break
    if (j == str(x)==str(count)):
        return True
    else:
        return False


def End_Chrome_Progress():
    subprocess.call("TASKKILL /f  /IM  CHROME.EXE")
    subprocess.call("TASKKILL /f  /IM  CHROMEDRIVER.EXE")


# 读取文件所有内容
def readFile_all(url):
    f = open(url, "r", encoding="utf-8")  # 从文件中读取内容
    t = f.read()
    f.close()
    return t


# 读取文件内容的函数，需要1个参数文件地址
def readFile(f):
    # f = open(url, "r")  # 从文件中读取内容
    t = f.readline()
    # f.close()
    return t


# 覆盖写入
def writeFile(url, text):
    f = open(url, "w", encoding="utf-8")
    f.write(text)
    f.close()


# 追加写入
def writeFile_append(url, text):
    f = open(url, "a", encoding="utf-8")
    f.write(get_time_hms()+":::"+text+'\n')
    f.close()


# 读取文件内容的函数，对内容进行处理，去掉冒号前面的内容
def readFileContent(url):
    f = open(url, "r", encoding="UTF-8")  # 从文件中读取内容
    t = f.readlines()
    path1 = get_pro_path()
    writeFile(path1 + '/add/Everydaylog.txt', "")  # 先清空所有内容
    writeFile(path1 + '/update/update_Everyday_log.txt', "")  # 先清空所有内容
    import re
    for i in t:
        if i == '\n':
            break
        mylist = re.split(":", i)
        # print(mylist)
        if mylist[0] == "实际工时":
            mylist[1] = mylist[1].replace('\n', "")
        writeFile_append(path1 + '/add/Everydaylog.txt', mylist[1])
        writeFile_append(path1 + '/update/update_Everyday_log.txt', mylist[1])
    f.close()
    return t


def get_time(type=1):
    import time
    if (type==1):
        t = time.strftime("%Y-%m-%d", time.localtime())
    else:
        t = time.strftime("%Y%m", time.localtime())
    # t = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
    return t


def get_time_add(days_aa):
    import time
    # t = time.strftime("%Y-%m-%d", datetime.datetime.now())
    tomorrow = (date.today() + timedelta(days=days_aa)).strftime("%Y-%m-%d")
    return tomorrow


def get_time_hms():
    import time
    # t = time.strftime("%Y-%m-%d", time.localtime())
    timedelta(days=1)
    t = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
    return t


def get_localhost_ip():
    import socket
    ip = socket.gethostbyname(socket.gethostname())
    ip = ip[0:5]
    print("http://" + ip)
    return "http://" + ip


# 获取当前项目的根目录的路径
def get_pro_path():
    import os
    # print('根据当前文件获取当前文件所在目录的路径', os.path.dirname(__file__))
    curPath = os.path.abspath(os.path.dirname(__file__))  # 获取当前文件的所在目录的绝对路径
    # print(curPath)  # C:\Users\xhs\Desktop\dbshop项目相关文档2\dbshop1\main
    # #将当前文件的所在目录的绝对路径进行分离,分离成C:\Users\xhs\Desktop\dbshop项目相关文档2\dbshop1  和main,存到元组中
    # print(os.path.split(curPath))
    rootPath = os.path.split(curPath)[0]  # [0]表示元组中的为一个元素
    # print('当前项目的根目录', rootPath)
    return rootPath


# 截图
def getErrorPhoto(chrome,type=1):
    #1正常截图 2错误截图
    import time
    if type==1:
        imgName = time.strftime("%Y%m%d_%H%M%S", time.localtime()) + ".png"
        pro_path = get_pro_path()  # 获取项目的根目录的路径
        image_path = pro_path + "//logs//" + imgName
        chrome.get_screenshot_as_file(image_path)
        return imgName, image_path
    else:
        imgName = time.strftime("%Y%m%d_%H%M%S", time.localtime()) + ".png"
        pro_path = get_pro_path()  # 获取项目的根目录的路径
        image_path = pro_path + "//logs_error//" + imgName
        chrome.get_screenshot_as_file(image_path)
        return imgName, image_path


#
def is_file_exist(filename):
    try:
        f = open(filename, 'r', encoding='utf-8')
    except:
        return False
    else:
        return True
#获取时间的分
def get_time_m():
    import time
    from datetime import datetime
    nows = int(time.time())
    # timestamp = 1591239600

    dt = datetime.fromtimestamp(nows)
    # print(dt.minute, dt.second)
    return dt.minute
    # if dt.minute == 0 and dt.second == 0:
    #     print('s ')
    # elif dt.minute == 50 and dt.second == 0:
    #     print('s ')
#判断时间区间，制定提交时间
def get_submit_time(m):
    if m>=0 and m<=10:
        return 20
    elif m>=11 and m<=20:
        return 30
    elif m>=21 and m<=30:
        return 40
    elif m>=31 and m<=40:
        return 50
    elif m>=41 and  m<=50:
        return 59
    elif m>=51 and m<=59:
        return 10
    else:
        return m+10
#判断时间区间，制定提交时间
#判断时间区间，制定提交时间
def get_submit_time1(m):
    if m >= 0 and m <= 30:
        return 40
    elif m >30 and m <= 59:
        return 10
    else:
        return m + 20


if __name__ == '__main__':
    # End_Chrome_Progress()
    # get_localhost_ip()
    # readFileContent(r'..\add\main_Everydaylog.txt')
    print(IsFileContentRight(r'..\add\main_Everydaylog.txt'))