milestone.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. import re
  2. import html
  3. def get_milestone(session, edit_milestone_url):
  4. """Fetch milestone details."""
  5. response = session.get(edit_milestone_url)
  6. if response.status_code == 200:
  7. title_match = re.search(r'<input[^>]*name=["\']title["\'][^>]*value=["\'](.*?)["\']', response.text, re.IGNORECASE)
  8. content_match = re.search(r'<textarea[^>]*name=["\']content["\'][^>]*>(.*?)</textarea>', response.text, re.IGNORECASE | re.DOTALL)
  9. title = title_match.group(1) if title_match else None
  10. content = content_match.group(1).strip() if content_match else None
  11. return {'title': title, 'content': content}
  12. else:
  13. print(f"Failed to fetch milestone: {response.status_code}")
  14. return None
  15. def append_item_to_identifier(encoded_content, identifier, new_item):
  16. """Append a new item to the block identified by the given identifier."""
  17. content = html.unescape(encoded_content)
  18. block_pattern = rf'(<!--\s*{identifier}\s*-->)(.*?)(<!--\s*/{identifier}\s*-->)'
  19. block_match = re.search(block_pattern, content, re.DOTALL)
  20. if not block_match:
  21. print(f"Block with identifier '{identifier}' not found.")
  22. return False
  23. start_marker = block_match.group(1)
  24. block_content = block_match.group(2).strip()
  25. end_marker = block_match.group(3)
  26. formatted_item = f"- [x] {new_item['username']}: [{new_item['title']}]({new_item['link_evoluz']})"
  27. updated_block_content = f"{block_content}\n{formatted_item}"
  28. updated_content = f"{start_marker}\n{updated_block_content}\n{end_marker}"
  29. return updated_content