import re path = '/opt/ai-os/products/ceo/projects/blog/vwg-content/tai-sao-chon-viet-nam/draft_vi_v1.md' with open(path, 'r', encoding='utf-8') as f: text = f.read() # the new content from test_builder import new_section_journey, new_section_comparison new_text = new_section_journey + "\n\n" + new_section_comparison + "\n\n" # replace the block pattern = r"(?s)## Hành trình biến tiệc cưới thành chuyến du lịch trọn vẹn.*?## Những yếu tố cần cân nhắc kỹ trước khi đưa ra quyết định" replacement = new_text + "## Những yếu tố cần cân nhắc kỹ trước khi đưa ra quyết định" updated_text = re.sub(pattern, replacement, text, count=1) if updated_text != text: with open(path, 'w', encoding='utf-8') as f: f.write(updated_text) print("PATCH SUCCESS") else: print("PATCH FAILED: pattern not found")