You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
resumen_backoffice/endpoint_enable.py

36 lines
1.1 KiB

from flask import Flask, request, jsonify
from flask_cors import CORS
import subprocess
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "http://resumen-sapian-cctel-02.dialbox.cloud"}})
@app.route('/execute_script', methods=['POST'])
def execute_script():
try:
data = request.get_json()
month = data.get('month')
if not month or not (1 <= int(month) <= 12):
return jsonify({"error": "Mes inválido. Debe estar entre 1 y 12."}), 400
script_path = "/home/concatenar_archivos.py"
command = ["python3", script_path, str(month)]
result = subprocess.run(command, capture_output=True, text=True)
if result.returncode == 0:
return jsonify({"message": "Script ejecutado correctamente.", "output": result.stdout}), 200
else:
return jsonify({"error": "Error al ejecutar el script.", "details": result.stderr}), 500
except Exception as e:
return jsonify({"error": "Error en el servidor.", "details": str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)