Spaces:
Runtime error
Runtime error
DmitrMakeev
commited on
Commit
•
18d4c31
1
Parent(s):
9fca449
Update google_db.py
Browse files- google_db.py +22 -16
google_db.py
CHANGED
@@ -9,19 +9,36 @@ from flask import jsonify
|
|
9 |
import requests
|
10 |
|
11 |
|
12 |
-
|
|
|
13 |
|
14 |
|
15 |
|
16 |
from flask import jsonify
|
17 |
import requests
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
def save_db():
|
20 |
err = 0
|
21 |
|
22 |
-
# Проверяем условие и выполняем кусок кода, если условие истинно
|
23 |
if api_variabl == request.args.get('api'):
|
24 |
-
# Получаем данные из request.args
|
25 |
dey_db = globs.dey
|
26 |
wek_db = globs.wek
|
27 |
v_hid_db = globs.v_hid
|
@@ -37,25 +54,14 @@ def save_db():
|
|
37 |
ec_B_eep_db = globs.ec_B_eep
|
38 |
ec_C_eep_db = globs.ec_C_eep
|
39 |
|
40 |
-
# Формируем данные для POST запроса
|
41 |
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}"
|
42 |
|
43 |
-
#
|
44 |
-
|
45 |
-
|
46 |
-
# Проверяем статус ответа
|
47 |
-
if response.status_code == 200:
|
48 |
-
err = 1
|
49 |
-
else:
|
50 |
-
err = 0
|
51 |
-
else:
|
52 |
-
err = 0
|
53 |
|
54 |
-
# Создаем JSON-объект для возвращения
|
55 |
response_data = {
|
56 |
"eep_set": globs.eep_set,
|
57 |
"err": err
|
58 |
}
|
59 |
|
60 |
-
# Возвращаем JSON-объект
|
61 |
return jsonify(response_data)
|
|
|
9 |
import requests
|
10 |
|
11 |
|
12 |
+
import asyncio
|
13 |
+
import aiohttp
|
14 |
|
15 |
|
16 |
|
17 |
from flask import jsonify
|
18 |
import requests
|
19 |
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
async def async_save_db(data):
|
26 |
+
async with aiohttp.ClientSession() as session:
|
27 |
+
async with session.post(google_url, data=data, headers={'Content-Type': 'application/x-www-form-urlencoded'}) as response:
|
28 |
+
# Просто проверяем статус код, не ожидая тела ответа
|
29 |
+
if response.status == 200:
|
30 |
+
return True
|
31 |
+
else:
|
32 |
+
return False
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
def save_db():
|
39 |
err = 0
|
40 |
|
|
|
41 |
if api_variabl == request.args.get('api'):
|
|
|
42 |
dey_db = globs.dey
|
43 |
wek_db = globs.wek
|
44 |
v_hid_db = globs.v_hid
|
|
|
54 |
ec_B_eep_db = globs.ec_B_eep
|
55 |
ec_C_eep_db = globs.ec_C_eep
|
56 |
|
|
|
57 |
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}"
|
58 |
|
59 |
+
# Запускаем асинхронный запрос в отдельном потоке
|
60 |
+
asyncio.create_task(async_save_db(data))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
|
|
62 |
response_data = {
|
63 |
"eep_set": globs.eep_set,
|
64 |
"err": err
|
65 |
}
|
66 |
|
|
|
67 |
return jsonify(response_data)
|