import sys from html import escape from check_quality import analyze r = analyze(sys.argv[1]) out = sys.argv[2] if len(sys.argv) > 2 else "report.html" missing_total = sum(len(h["missing"]) for h in r["hosts"].values()) cards = [ ("전체 줄", r["total"], ""), ("파싱 실패", len(r["parse_failed"]), "bad"), ("중복", len(r["duplicates"]), "bad"), ("유실", missing_total, "bad"), ("시간 이상", len(r["delay_problems"]), "bad"), ("순서 역전", len(r["reversals"]), "bad"), ] card_html = "".join( f'
{n}{escape(name)}
' for name, n, cls in cards ) host_rows = "".join( f"{escape(h)}{v['count']}{v['first']}~{v['last']}" f"{escape(str(v['missing']) if v['missing'] else '없음')}" for h, v in r["hosts"].items() ) line_rows = "" for n, line in enumerate(r["lines"], 1): why = r["bad_lines"].get(n, "") cls = ' class="flag"' if why else "" line_rows += f"{n}{escape(line)}{escape(why)}" html = f""" 로그 품질 점검 보고서
로그 품질 점검 보고서 ({escape(sys.argv[1])})
{card_html}

호스트별 일련번호

{host_rows}
호스트받은 건수번호 범위유실된 번호

줄별 판정

{line_rows}
줄내용문제
""" open(out, "w", encoding="utf-8").write(html) print("saved", out)