Simon Bruder
3912d29530
All checks were successful
continuous-integration/drone/push Build is passing
quart: async flask pyppeteer: puppeteer but in python → no nodejs in container
55 lines
1.4 KiB
Python
Executable file
55 lines
1.4 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
from pyppeteer import launch
|
|
from quart import Quart, request, render_template, url_for, redirect
|
|
from subprocess import run
|
|
import asyncio
|
|
import os
|
|
|
|
app = Quart(__name__)
|
|
|
|
|
|
def run_check(*args, **kwargs):
|
|
return run(*args, **kwargs, check=True)
|
|
|
|
|
|
async def gen_pdf(name):
|
|
browser = await launch(args=["--no-sandbox"])
|
|
page = await browser.newPage()
|
|
await page.goto("file://" + os.path.join(os.getcwd(), "namensschild.html"))
|
|
await page.evaluate(f"document.querySelector('#name').innerText = '{name}'")
|
|
await page.pdf(path="static/namensschild.pdf", width="180px", height="60px")
|
|
await browser.close()
|
|
|
|
|
|
@app.route("/")
|
|
async def index():
|
|
return await render_template("index.html.j2")
|
|
|
|
|
|
@app.route("/generate")
|
|
async def generate():
|
|
name = request.args["name"]
|
|
await gen_pdf(name)
|
|
run_check(
|
|
["inkscape", "-T", "-E", "static/namensschild.eps", "static/namensschild.pdf",]
|
|
)
|
|
run_check(
|
|
[
|
|
"pstoedit",
|
|
"-q",
|
|
"-flat",
|
|
"0.0001",
|
|
"-dt",
|
|
"-f",
|
|
"dxf: -polyaslines -mm",
|
|
"static/namensschild.eps",
|
|
"static/namensschild.dxf",
|
|
]
|
|
)
|
|
run_check(["openscad", "-o", f"static/{name}.stl", "namensschild.scad"])
|
|
return redirect(url_for("static", filename=f"{name}.stl"), code=302)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(debug=True)
|