flask_inference_api_g / api_logic.py
DmitrMakeev's picture
Update api_logic.py
86c985f verified
raw
history blame
1.97 kB
from flask import request, jsonify
import globs
import os
api_variable = os.getenv('api_key')
# Устанавливаем значения по умолчанию
globs.ph_set = 0
globs.ph_on_set = 0
globs.ec_set = 0
globs.ec_A_set = 0
globs.ec_B_set = 0
globs.ec_C_set = 0
globs.l_ON_h_set = 0
globs.l_ON_m_set = 0
globs.l_OFF_h_set = 0
globs.l_OFF_m_set = 0
globs.ec_t_Voz_set = 0
globs.eep_set = 0
def api():
err = 0
if api_variable == request.args.get('api'):
globs.ph_set = float(request.args.get('ph_set', 0.0))
globs.ph_on_set = float(request.args.get('ph_on_set', 0.0))
globs.ec_set = float(request.args.get('ec_set', 0.0))
globs.ec_A_set = float(request.args.get('ec_A_set', 0.0))
globs.ec_B_set = float(request.args.get('ec_B_set', 0.0))
globs.ec_C_set = float(request.args.get('ec_C_set', 0.0))
globs.l_ON_h_set = int(request.args.get('l_ON_h_set', 0))
globs.l_ON_m_set = int(request.args.get('l_ON_m_set', 0))
globs.l_OFF_h_set = int(request.args.get('l_OFF_h_set', 0))
globs.l_OFF_m_set = int(request.args.get('l_OFF_m_set', 0))
globs.ec_t_Voz_set = int(request.args.get('ec_t_Voz_set', 0))
globs.eep_set = int(request.args.get('eep_set', 0))
err = 1
else:
err = 0
# Формируем ответ в нужном формате
response = {
"OFF_h_set": int(globs.l_OFF_h_set),
"OFF_m_set": int(globs.l_OFF_m_set),
"ON_h_set": int(globs.l_ON_h_set),
"ON_m_set": int(globs.l_ON_m_set),
"ec_A_set": float(globs.ec_A_set),
"ec_B_set": float(globs.ec_B_set),
"ec_C_set": float(globs.ec_C_set),
"ec_set": float(globs.ec_set),
"ec_t_Voz_set": int(globs.ec_t_Voz_set),
"eep_set": int(globs.eep_set),
"err": int(err),
"ph_on_set": float(globs.ph_on_set),
"ph_set": float(globs.ph_set)
}
return jsonify(response)