import re
import html
def get_milestone(session, edit_milestone_url):
"""Fetch milestone details."""
response = session.get(edit_milestone_url)
if response.status_code == 200:
title_match = re.search(r']*name=["\']title["\'][^>]*value=["\'](.*?)["\']', response.text, re.IGNORECASE)
content_match = re.search(r'', response.text, re.IGNORECASE | re.DOTALL)
title = title_match.group(1) if title_match else None
content = content_match.group(1).strip() if content_match else None
return {'title': title, 'content': content}
else:
print(f"Failed to fetch milestone: {response.status_code}")
return None
def append_item_to_identifier(encoded_content, identifier, new_item):
"""Append a new item to the block identified by the given identifier."""
content = html.unescape(encoded_content)
block_pattern = rf'()(.*?)()'
block_match = re.search(block_pattern, content, re.DOTALL)
if not block_match:
print(f"Block with identifier '{identifier}' not found.")
return False
start_marker = block_match.group(1)
block_content = block_match.group(2).strip()
end_marker = block_match.group(3)
formatted_item = f"- [x] {new_item['username']}: [{new_item['title']}]({new_item['link_evoluz']})"
updated_block_content = f"{block_content}\n{formatted_item}"
updated_content = f"{start_marker}\n{updated_block_content}\n{end_marker}"
return updated_content