template = r""" \header {{ tagline = "" }} {content} """ def render(user: str, source: str, png: bool = True) -> str: import tempfile import subprocess import utils import os fmt = template.format(content=source) tmp = tempfile.NamedTemporaryFile(delete=False) tmp.write(bytes(fmt, encoding="utf8")) tmp.close() if png: subprocess.run(["lilypond", "-d", "preview", "--png", "-dresolution=500", tmp.name], cwd="/tmp") return tmp.name + ".preview.png" subprocess.run(["lilypond", "-d", "preview", "--svg", tmp.name], cwd="/tmp") return tmp.name + "preview.svg"