import re,os

def read_last_line(file_path):
    with open(file_path, 'r') as f:
        lines = f.readlines()
        last_line = lines[-1]  # 获取最后一行
    return last_line

def parse_curl_line(line: str):
    m = re.match(r"(\d+)\s+(\S+)\s+(\d+)\s+(\S+)", line)
    if not m:
        return None

    return {
        "percent_now": int(m.group(1)),
        "size_now": m.group(2),
        "percent_total": int(m.group(3)),
        "size_total": m.group(4),
    }

def is_complete(info):
    if not info:
        return False

    return (
        info["percent_now"] == 100 and
        info["percent_total"] == 100 and
        info["size_now"] == info["size_total"]
    )

def get_log():
    # 获取当前目录
    current_directory = os.getcwd()

    # 遍历当前目录中的所有文件
    log_files = [f for f in os.listdir(current_directory) if f.endswith('.log')]
    return log_files

def main():
    ok = []
    no = []
    log_files = get_log()
    for path in log_files:
        x = parse_curl_line(read_last_line(path))
        if is_complete(x):
            ok.append(path)
        else:
            no.append(path)
    
    print(f"下载完成{ok}")

    print(f"未下载完成{no}")



if __name__ == '__main__':
    main()
