Files
atm-curs-dl/render_html.py
Claude Agent b239f04eb6 Proiect descărcare + transcriere curs ATM (trading, Bogdan Jinga)
Pipeline audio-only (fără video pe disc) prin ffmpeg direct din URL CloudFront,
transcriere cu faster-whisper (CPU), sumarizări structurate cu diagrame SVG
la scară reală (STYLE.md documentează toate cerințele de format).
2026-09-11 07:36:17 +00:00

68 lines
2.0 KiB
Python

"""
Render every summaries/**/*.md to a sibling .html — mobile-readable (viewport
meta + real font size), served alongside the .md via `tailscale serve`.
Also (re)writes summaries/index.html linking every rendered page.
Run after adding/editing any summary.
"""
from pathlib import Path
import markdown
ROOT = Path(__file__).parent / "summaries"
PAGE_TEMPLATE = """<!DOCTYPE html>
<html lang="ro">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{title}</title>
<style>
body {{ max-width: 720px; margin: 0 auto; padding: 16px 20px 60px;
font: 18px/1.55 -apple-system, Segoe UI, Roboto, sans-serif;
color: #1a1a1a; }}
h1 {{ font-size: 1.4em; }}
h2 {{ font-size: 1.15em; margin-top: 1.6em; border-top: 1px solid #ddd; padding-top: .8em; }}
code {{ font-size: .95em; background: #f0f0f0; padding: .1em .3em; border-radius: 3px; }}
a {{ color: #1a5fb4; }}
hr {{ border: none; border-top: 1px solid #ddd; margin: 2em 0; }}
em {{ color: #555; }}
</style>
</head>
<body>
{body}
</body>
</html>
"""
def render_file(md_path: Path) -> Path:
text = md_path.read_text(encoding="utf-8")
body = markdown.markdown(text, extensions=["extra"])
title = text.splitlines()[0].lstrip("# ").strip() if text else md_path.stem
html_path = md_path.with_suffix(".html")
html_path.write_text(PAGE_TEMPLATE.format(title=title, body=body), encoding="utf-8")
return html_path
def write_index(pages: list[Path]):
items = "\n".join(
f'<li><a href="{p.relative_to(ROOT)}">{p.parent.name} / {p.stem}</a></li>'
for p in sorted(pages)
)
(ROOT / "index.html").write_text(
PAGE_TEMPLATE.format(title="ATM — Sumarizări", body=f"<h1>ATM — Sumarizări</h1><ul>{items}</ul>"),
encoding="utf-8",
)
def main():
md_files = sorted(ROOT.glob("*/*.md"))
pages = [render_file(f) for f in md_files]
write_index(pages)
print(f"Rendered {len(pages)} page(s) + index.html")
if __name__ == "__main__":
main()