Skip to content

Commit f710b51

Browse files
authored
refact: HISTORY_FILE에 현재 달 기록을 추가하는 방식 변경, 불필요한 달(Month) 비교 구문 제거
+ 추가로 단계별 디버깅용 출력문 추가
1 parent a826633 commit f710b51

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

_MonthlyChallenges/update_dashboard.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,37 @@ def generate_dashboard(scoreboard):
3838
md += "\n\n"
3939
return md
4040

41-
def archive_current_month(scoreboard):
42-
# HISTORY_FILE에 현재 달 기록을 추가 (append 방식)
43-
dashboard_md = generate_dashboard(scoreboard)
41+
def archive_current_month():
42+
"""
43+
HISTORY_FILE에 현재 달 기록을 추가 (append 방식)
44+
"""
45+
# 1. DASHBOARD.md 읽기
46+
try:
47+
with open(DASHBOARD_FILE, "r", encoding="utf-8") as db:
48+
dashboard_md = db.read()
49+
except FileNotFoundError:
50+
print("[Archive] DASHBOARD.md not found. Please create DASHBOARD.md first.")
51+
return
52+
53+
# 2. HISTORY.md에 append
4454
with open(HISTORY_FILE, "a", encoding="utf-8") as f:
4555
f.write(dashboard_md)
46-
f.write("\n\n") # 구분을 위한 빈 줄 추가
47-
print("HISTORY.md 업데이트 완료!")
56+
f.write("\n\n") # 구분용 빈 줄
57+
print("[Archive] Appended current dashboard to HISTORY.md successfully.")
4858

4959
def update_dashboard():
5060
# 1. scoreboard.json 로드
61+
print("[Step 1] Loading scoreboard file...")
5162
if not os.path.exists(SCOREBOARD_FILE):
52-
print(f"{SCOREBOARD_FILE} 파일이 없습니다.")
63+
print(f"[Step 1] File not found: {SCOREBOARD_FILE}")
5364
return
5465

5566
with open(SCOREBOARD_FILE, "r", encoding="utf-8") as f:
5667
scoreboard = json.load(f)
68+
print("[Step 1] Loaded scoreboard data.")
5769

5870
# 2. 기존 파일 구조가 새 형식("month", "users")이 아니라면 변환
71+
print("[Step 2] Verifying scoreboard structure...")
5972
if "month" not in scoreboard or "users" not in scoreboard:
6073
# 기존 구조는 사용자 이름이 최상위 키인 형태
6174
scoreboard = {
@@ -65,30 +78,15 @@ def update_dashboard():
6578
# 새 형식으로 저장
6679
with open(SCOREBOARD_FILE, "w", encoding="utf-8") as f:
6780
json.dump(scoreboard, f, ensure_ascii=False, indent=2)
68-
print("기존 scoreboard 형식을 새 구조로 변환하였습니다.")
69-
70-
# 3. 현재 달 확인 및 월 초기화 처리
71-
current_month = datetime.now().strftime("%Y-%m")
72-
stored_month = scoreboard.get("month", current_month)
73-
print(f"현재 달: {current_month}, 저장된 달: {stored_month}")
74-
75-
if stored_month != current_month:
76-
print(f"새로운 달({current_month})로 넘어감 - 이전 달({stored_month}) 기록을 히스토리에 저장합니다.")
77-
archive_current_month(scoreboard)
78-
# scoreboard 초기화: users는 빈 dict, month는 현재 달로 갱신
79-
scoreboard = {
80-
"month": current_month,
81-
"users": {}
82-
}
83-
with open(SCOREBOARD_FILE, "w", encoding="utf-8") as f:
84-
json.dump(scoreboard, f, ensure_ascii=False, indent=2)
81+
print("[Step 2] Converted existing scoreboard format to new structure.")
8582

86-
# 4. DASHBOARD.md 파일 생성 및 업데이트
83+
# 3. DASHBOARD.md 파일 생성 및 업데이트
84+
print("[Step 3] Generating dashboard content...")
8785
md_content = generate_dashboard(scoreboard)
8886
with open(DASHBOARD_FILE, "w", encoding="utf-8") as f:
8987
f.write(md_content)
9088

91-
print("DASHBOARD.md 업데이트 완료!")
89+
print("[Step 3] DASHBOARD.md updated successfully.")
9290

9391
if __name__ == '__main__':
9492
update_dashboard()

0 commit comments

Comments
 (0)