Spaces:
Sleeping
Sleeping
from flask import request, jsonify | |
import globs | |
import os | |
import asyncio | |
import aiohttp | |
api_variabl = os.getenv('api_key') | |
google_url = os.getenv('goo_url') | |
async def async_save_db(data): | |
async with aiohttp.ClientSession() as session: | |
async with session.post(google_url, data=data, headers={'Content-Type': 'application/x-www-form-urlencoded'}) as response: | |
# Просто проверяем статус код, не ожидая тела ответа | |
return response.status == 200 | |
def save_db(): | |
err = 0 | |
if api_variabl == request.args.get('api'): | |
dey_db = globs.dey | |
wek_db = globs.wek | |
hours = globs.v_hid | |
minutes = globs.v_min | |
time_db = f"{hours}:{minutes}" | |
ph_db = globs.ph | |
ec_db = globs.ec | |
tS_db = globs.tS | |
tA_db = globs.tA | |
hDm_db = globs.hDm | |
sVen_db = globs.sVen | |
l_ON_h = globs.l_ON_h_eep | |
l_ON_m = globs.l_ON_m_eep | |
l_OFF_h = globs.l_OFF_h_eep | |
l_OFF_m = globs.l_OFF_m_eep | |
l_ON = f"{l_ON_h}:{l_ON_m}" | |
l_OFF = f"{l_OFF_h}:{l_OFF_m}" | |
ec_A_eep_db = globs.ec_A_eep | |
ec_B_eep_db = globs.ec_B_eep | |
ec_C_eep_db = globs.ec_C_eep | |
data = f"action=addData&dey={dey_db}&wek={wek_db}&time={time_db}&ph={ph_db}&ec={ec_db}&tS={tS_db}&tA={tA_db}&hDm={hDm_db}&sVen={sVen_db}&l_ON={l_ON}&l_OFF={l_OFF}&ec_A_eep={ec_A_eep_db}&ec_B_eep={ec_B_eep_db}&ec_C_eep={ec_C_eep_db}" | |
# Запускаем асинхронный запрос в отдельном потоке | |
loop = asyncio.new_event_loop() | |
asyncio.set_event_loop(loop) | |
result = loop.run_until_complete(async_save_db(data)) | |
loop.close() | |
err = 1 if result else 0 | |
response_data = { | |
"eep_set": globs.eep_set, | |
"err": err | |
} | |
return jsonify(response_data) |