This repository has been archived on 2020-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
namensschilder/server.py
2019-03-27 19:30:59 +00:00

25 lines
893 B
Python
Executable file

#!/usr/bin/env python3
from flask import Flask, request, render_template, url_for, redirect
from lxml import etree
from subprocess import run
app = Flask(__name__)
def run_check(*args, **kwargs):
return run(*args, **kwargs, check=True)
@app.route("/")
def hello():
try:
name = request.args['name']
run_check(['node', 'print.js', 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)
except KeyError:
return render_template('index.html.j2')
if __name__ == '__main__':
app.run(host='0.0.0.0')