import sys from pathlib import Path from openpyxl import load_workbook YEAR_NO_DATA = { "2022": {"377", "400", "636", "643", "805", "819", "820", "824", "843", "932", "936", "950", "951"}, "2023": {"263", "417", "636", "805", "819", "843", "932", "933", "936", "950", "951"}, "2024": {"116", "263", "417", "805", "950", "951"}, } year = sys.argv[1] base = Path(r"\\wsl.localhost\Ubuntu\home\b17301\WEHAGO_DB\data_download") / year target = max(base.glob("ledger_*.xlsx"), key=lambda item: item.stat().st_mtime) no_data = YEAR_NO_DATA[year] workbook = load_workbook(target) status_ws = workbook["계정별상태"] error_ws = workbook["오류_누락"] for row in status_ws.iter_rows(min_row=2): code = str(row[0].value) if code in no_data: row[2].value = "데이터없음" row[5].value = f"{year}년 WEHAGO 계정별원장 화면에서 거래 데이터가 없어 다운로드 파일을 생성하지 않았습니다." for row_index in range(2, error_ws.max_row + 1): for col_index in range(1, error_ws.max_column + 1): error_ws.cell(row_index, col_index).value = None write_row = 2 for row in status_ws.iter_rows(min_row=2, values_only=True): code, name, status, file_name, _row_count, message = row[:6] if status != "정상": for col_index, value in enumerate([code, name, status, file_name, message], start=1): error_ws.cell(write_row, col_index).value = value write_row += 1 workbook.save(target) print(target)