Spaces:
Sleeping
Sleeping
File size: 1,803 Bytes
0827625 18d4c31 1ce6a36 9a9069e 8146e53 18d4c31 2123df3 18d4c31 9a9069e 0827625 3ae0225 0827625 3ae0225 0827625 9fca449 c134c84 9a9069e c134c84 1ce6a36 0827625 9a9069e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
from flask import request, jsonify
import globs
import os
import asyncio
import aiohttp
from threading import Thread
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:
# Просто проверяем статус код, не ожидая тела ответа
if response.status == 200:
return True
else:
return False
def save_db():
err = 0
if api_variabl == request.args.get('api'):
dey_db = globs.dey
wek_db = globs.wek
v_hid_db = globs.v_hid
v_min_db = globs.v_min
ph_db = globs.ph
ec_db = globs.ec
tS_db = globs.tS
tA_db = globs.tA
hDm_db = globs.hDm
sVen_db = globs.sVen
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}&v_hid={v_hid_db}&v_min={v_min_db}&ph={ph_db}&ec={ec_db}&tS={tS_db}&tA={tA_db}&hDm={hDm_db}&sVen={sVen_db}&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)
loop.run_until_complete(async_save_db(data))
loop.close()
response_data = {
"eep_set": globs.eep_set,
"err": err
}
return jsonify(response_data)
@app.route("/save_db", methods=['GET'])
def handle_save_db():
response = save_db()
return response |