31 lines
940 B
Python
31 lines
940 B
Python
import re
|
|
from config.settings import settings
|
|
|
|
class ReadmeEditor:
|
|
def __init__(self, file_path: str = None):
|
|
self.file_path = file_path or settings.README_PATH
|
|
|
|
def update_section(self, new_content: str):
|
|
with open(self.file_path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# Regex to find content between markers
|
|
pattern = re.compile(
|
|
f"({re.escape(settings.START_MARKER)})(.*?)({re.escape(settings.END_MARKER)})",
|
|
re.DOTALL
|
|
)
|
|
|
|
if not pattern.search(content):
|
|
print(f"Markers {settings.START_MARKER} and {settings.END_MARKER} not found in {self.file_path}")
|
|
return False
|
|
|
|
updated_content = pattern.sub(
|
|
f"\\1\n\n{new_content}\n\n\\3",
|
|
content
|
|
)
|
|
|
|
with open(self.file_path, 'w', encoding='utf-8') as f:
|
|
f.write(updated_content)
|
|
|
|
return True
|