Update cemento.py
This commit is contained in:
42
cemento.py
42
cemento.py
@@ -1,23 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
import subprocess
|
|
||||||
from flask import Flask, render_template, request
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
|
||||||
def index():
|
|
||||||
res = None
|
|
||||||
if request.method == 'POST':
|
|
||||||
try:
|
|
||||||
# Recupero dati dal form e calcolo
|
|
||||||
v = request.form.get('v', '0')
|
|
||||||
ps = request.form.get('ps', '0')
|
|
||||||
ts = request.form.get('ts', '0')
|
|
||||||
res = {"vol": v, "peso": ps, "tot_sacc": ts}
|
|
||||||
except:
|
|
||||||
res = None
|
|
||||||
return render_template('index.html', res=res, form=request.form)
|
|
||||||
|
|
||||||
@app.route('/stampa_pdf', methods=['POST'])
|
@app.route('/stampa_pdf', methods=['POST'])
|
||||||
def stampa_pdf():
|
def stampa_pdf():
|
||||||
try:
|
try:
|
||||||
@@ -25,29 +5,25 @@ def stampa_pdf():
|
|||||||
ps = request.form.get('ps', '0')
|
ps = request.form.get('ps', '0')
|
||||||
ts = request.form.get('ts', '0')
|
ts = request.form.get('ts', '0')
|
||||||
|
|
||||||
# Formattazione PostScript per garantire che il PDF non sia vuoto
|
# Testo formattato in PostScript per evitare PDF vuoti
|
||||||
ps_content = f"""%!PS
|
ps_content = f"""%!PS
|
||||||
/Helvetica findfont 16 scalefont setfont
|
/Helvetica findfont 14 scalefont setfont
|
||||||
100 750 moveto (REPORT CALCOLO CEMENTO) show
|
100 750 moveto (REPORT CALCOLO CEMENTO) show
|
||||||
/Helvetica findfont 12 scalefont setfont
|
100 720 moveto (Volume: {v} m3) show
|
||||||
100 720 moveto (Volume totale: {v} m3) show
|
100 700 moveto (Peso: {ps} kg) show
|
||||||
100 700 moveto (Peso stimato: {ps} kg) show
|
|
||||||
100 680 moveto (Totale sacchetti: {ts}) show
|
100 680 moveto (Totale sacchetti: {ts}) show
|
||||||
100 650 moveto (Data: 20/01/2026) show
|
|
||||||
showpage"""
|
showpage"""
|
||||||
|
|
||||||
# Esecuzione tramite docker exec (metodo testato con successo via root)
|
# Comando per iniettare i dati nel container
|
||||||
comando = ["docker", "exec", "-i", "cups-pdf-server", "lp", "-d", "Virtual_PDF"]
|
comando = ["docker", "exec", "-i", "cups-pdf-server", "lp", "-d", "Virtual_PDF"]
|
||||||
|
|
||||||
|
# Esecuzione del comando passandogli il testo PostScript
|
||||||
processo = subprocess.run(comando, input=ps_content.encode('utf-8'), capture_output=True)
|
processo = subprocess.run(comando, input=ps_content.encode('utf-8'), capture_output=True)
|
||||||
|
|
||||||
if processo.returncode == 0:
|
if processo.returncode == 0:
|
||||||
return "OK - PDF creato con successo!"
|
return "OK - PDF generato correttamente!"
|
||||||
else:
|
else:
|
||||||
return f"Errore container: {processo.stderr.decode()}"
|
return f"Errore container: {processo.stderr.decode()}"
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Errore script: {str(e)}"
|
return f"Errore script: {str(e)}"
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
# Porta 5000 per il tuo Proxy Reverse
|
|
||||||
app.run(host='0.0.0.0', port=5000)
|
|
||||||
Reference in New Issue
Block a user