@@ -134,33 +134,57 @@ def create_issue(github, repo, participant_name, date_str, penalty_type, amount)
134134 return None
135135
136136def update_readme_penalty (participant_name , amount = 5000 ):
137- """README.md의 누적 적립금을 업데이트합니다."""
137+ """README.md의 합류 후 누적 적립금을 업데이트합니다."""
138138 # README.md 경로 확인 (src/README.md 또는 README.md)
139139 readme_path = 'src/README.md' if os .path .exists ('src/README.md' ) else 'README.md'
140-
140+
141141 try :
142142 with open (readme_path , 'r' , encoding = 'utf-8' ) as f :
143143 content = f .read ()
144-
145- # 누적 적립금 섹션 찾기
144+
145+ # 합류 후 섹션만 찾기
146+ section_pattern = r'(<!-- 합류후_START -->)(.*?)(<!-- 합류후_END -->)'
147+ section_match = re .search (section_pattern , content , re .DOTALL )
148+
149+ if not section_match :
150+ print (f"❌ 실패: 합류 후 테이블 섹션을 찾을 수 없습니다." )
151+ return False
152+
153+ section = section_match .group (2 )
154+
155+ # 해당 참여자의 금액 업데이트
146156 pattern = rf'(\| { re .escape (participant_name )} \| )(\d+)원'
147-
157+
148158 def replace_amount (match ):
149159 current_amount = int (match .group (2 ))
150160 new_amount = current_amount + amount
151161 return f'{ match .group (1 )} { new_amount } 원'
152-
153- new_content = re .sub (pattern , replace_amount , content )
154-
155- if new_content != content :
156- with open (readme_path , 'w' , encoding = 'utf-8' ) as f :
157- f .write (new_content )
158- # 로그는 호출하는 쪽에서 출력하므로 여기서는 출력하지 않음
159- return True
160- else :
162+
163+ new_section = re .sub (pattern , replace_amount , section )
164+
165+ if new_section == section :
161166 print (f"❌ 실패: { participant_name } 님을 찾을 수 없습니다." )
162167 return False
163-
168+
169+ # 총액 재계산 (테이블 행에서만 추출)
170+ amounts = re .findall (r'^\| \S+ \| (\d+)원' , new_section , re .MULTILINE )
171+ total = sum (int (a ) for a in amounts )
172+
173+ # 총액 업데이트
174+ new_section = re .sub (
175+ r'\*\*총 추가 회식비: [\d,]+원\*\*' ,
176+ f'**총 추가 회식비: { total :,} 원**' ,
177+ new_section
178+ )
179+
180+ # 섹션을 원본에 다시 넣기
181+ new_content = content [:section_match .start (2 )] + new_section + content [section_match .end (2 ):]
182+
183+ with open (readme_path , 'w' , encoding = 'utf-8' ) as f :
184+ f .write (new_content )
185+ # 로그는 호출하는 쪽에서 출력하므로 여기서는 출력하지 않음
186+ return True
187+
164188 except Exception as e :
165189 print (f"README.md 업데이트 중 오류 발생: { e } " )
166190 return False
0 commit comments