#!/usr/bin/env python3
import re
from datetime import datetime
from xml.sax.saxutils import escape
rss_path = "/rss/index.xml"
md_path = "/updates/updates.md"
with open(md_path, "r", encoding="utf-8") as f:
content = f.read()
entries = re.findall(r"## (\d{4}-\d{2}-\d{2}) - (.+?)\n(.+?)(?=\n## |\Z)", content, re.DOTALL)
rss_items = ""
for date_str, title, description in entries:
pubdate = datetime.strptime(date_str, "%Y-%m-%d").strftime("%a, %d %b %Y 12:00:00 GMT")
rss_items += f""" -
{escape(title.strip())}
http://rss/index.xml#{escape(title.strip().replace(" ", "-").lower())}
{pubdate}
{escape(description.strip())}
\n"""
rss = f"""
Updates serveur
http://rss/index.xml
Changelog des services Tellserv
{rss_items}
"""
with open(rss_path, "w", encoding="utf-8") as f:
f.write(rss)
print("Flux RSS généré.")