Update cemento.py
This commit is contained in:
30
cemento.py
30
cemento.py
@@ -2,24 +2,22 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import math
|
import math
|
||||||
import requests # Usiamo requests per bypassare l'errore del comando 'lp'
|
import socket # Usiamo i socket per evitare l'errore "lp not found"
|
||||||
import time
|
import time
|
||||||
from flask import Flask, render_template, request, Response
|
from flask import Flask, render_template, request, Response
|
||||||
|
|
||||||
# Configurazione per Synology
|
|
||||||
sys.path.append('/var/services/homes/Francesco/.local/lib/python3.8/site-packages')
|
sys.path.append('/var/services/homes/Francesco/.local/lib/python3.8/site-packages')
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# CONFIGURAZIONE STAMPA CUPS
|
# Configurazione CUPS
|
||||||
CUPS_URL = "http://192.168.1.14:6310/printers/Virtual_PDF"
|
CUPS_IP = "192.168.1.14"
|
||||||
OUTPUT_DIR = "/volume1/docker/cups-pdf/output"
|
CUPS_PORT = 631 # Porta standard IPP/CUPS
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def index():
|
def index():
|
||||||
res = None
|
res = None
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# Calcoli originali preservati
|
|
||||||
try:
|
try:
|
||||||
d = request.form
|
d = request.form
|
||||||
def to_m(v, u):
|
def to_m(v, u):
|
||||||
@@ -41,7 +39,8 @@ def index():
|
|||||||
|
|
||||||
tot_s, costo_t = 0, 0
|
tot_s, costo_t = 0, 0
|
||||||
for m in mats:
|
for m in mats:
|
||||||
if p[m] <= 0: # Correzione bug ghiaia
|
# Correzione bug per valori a zero
|
||||||
|
if p[m] <= 0:
|
||||||
res[f's_{m}'] = 0
|
res[f's_{m}'] = 0
|
||||||
res[f'cost_{m}'] = "0.00"
|
res[f'cost_{m}'] = "0.00"
|
||||||
continue
|
continue
|
||||||
@@ -62,25 +61,24 @@ def index():
|
|||||||
else: res[f'bc_{m}'] = f"{((p[m]/somma_p)*peso_tot/w[m])/n_c:.2f}"
|
else: res[f'bc_{m}'] = f"{((p[m]/somma_p)*peso_tot/w[m])/n_c:.2f}"
|
||||||
res["bc_aq"] = f"{(vol*150)/n_c:.2f}"
|
res["bc_aq"] = f"{(vol*150)/n_c:.2f}"
|
||||||
except: res = None
|
except: res = None
|
||||||
|
return render_template('index.html', res=res, form=request.form)
|
||||||
return render_template('index.html', res=res, form=request.form, rev="Rev.11.0")
|
|
||||||
|
|
||||||
@app.route('/stampa_pdf', methods=['POST'])
|
@app.route('/stampa_pdf', methods=['POST'])
|
||||||
def stampa_pdf():
|
def stampa_pdf():
|
||||||
f = request.form
|
f = request.form
|
||||||
testo = f"REPORT CALCOLO CEMENTO\nVol: {f.get('res_vol')} m3\nCosto: {f.get('res_costo_t')} EUR"
|
testo = f"REPORT CALCOLO\nVolume: {f.get('res_vol')} m3\nSacchetti: {f.get('res_tot_s')}\nCosto: {f.get('res_costo_t')} EUR"
|
||||||
try:
|
try:
|
||||||
# Invio diretto via HTTP POST a CUPS
|
# Invio diretto al socket del container per evitare l'errore 'lp'
|
||||||
requests.post(CUPS_URL, data=testo.encode('utf-8'), timeout=5)
|
with socket.create_connection((CUPS_IP, CUPS_PORT), timeout=5) as s:
|
||||||
time.sleep(2)
|
s.sendall(testo.encode('utf-8'))
|
||||||
return "OK - File inviato a Virtual_PDF"
|
return "OK - Inviato a Virtual_PDF"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Errore CUPS: {str(e)}"
|
return f"Errore di rete CUPS: {str(e)}"
|
||||||
|
|
||||||
@app.route('/download', methods=['POST'])
|
@app.route('/download', methods=['POST'])
|
||||||
def download():
|
def download():
|
||||||
f = request.form
|
f = request.form
|
||||||
report = f"REPORT\nVolume: {f.get('res_vol')} m3\nSacchetti: {f.get('res_tot_s')}"
|
report = f"REPORT TECNICO\nVolume: {f.get('res_vol')} m3\nTotale: {f.get('res_tot_s')} sacchetti"
|
||||||
return Response(report, mimetype="text/plain", headers={"Content-disposition":"attachment;filename=Report.txt"})
|
return Response(report, mimetype="text/plain", headers={"Content-disposition":"attachment;filename=Report.txt"})
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user