DmitrMakeev
commited on
Commit
•
e90fdaa
1
Parent(s):
57c78cf
Update google_db.py
Browse files- google_db.py +5 -10
google_db.py
CHANGED
@@ -7,21 +7,14 @@ import aiohttp
|
|
7 |
api_variabl = os.getenv('api_key')
|
8 |
google_url = os.getenv('goo_url')
|
9 |
|
10 |
-
err = 0
|
11 |
-
|
12 |
async def async_save_db(data):
|
13 |
async with aiohttp.ClientSession() as session:
|
14 |
async with session.post(google_url, data=data, headers={'Content-Type': 'application/x-www-form-urlencoded'}) as response:
|
15 |
# Просто проверяем статус код, не ожидая тела ответа
|
16 |
-
|
17 |
-
return True
|
18 |
-
err = 1
|
19 |
-
else:
|
20 |
-
return False
|
21 |
-
err = 0
|
22 |
|
23 |
def save_db():
|
24 |
-
|
25 |
|
26 |
if api_variabl == request.args.get('api'):
|
27 |
dey_db = globs.dey
|
@@ -45,9 +38,11 @@ def save_db():
|
|
45 |
# Запускаем асинхронный запрос в отдельном потоке
|
46 |
loop = asyncio.new_event_loop()
|
47 |
asyncio.set_event_loop(loop)
|
48 |
-
loop.run_until_complete(async_save_db(data))
|
49 |
loop.close()
|
50 |
|
|
|
|
|
51 |
response_data = {
|
52 |
"eep_set": globs.eep_set,
|
53 |
"err": err
|
|
|
7 |
api_variabl = os.getenv('api_key')
|
8 |
google_url = os.getenv('goo_url')
|
9 |
|
|
|
|
|
10 |
async def async_save_db(data):
|
11 |
async with aiohttp.ClientSession() as session:
|
12 |
async with session.post(google_url, data=data, headers={'Content-Type': 'application/x-www-form-urlencoded'}) as response:
|
13 |
# Просто проверяем статус код, не ожидая тела ответа
|
14 |
+
return response.status == 200
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def save_db():
|
17 |
+
err = 0
|
18 |
|
19 |
if api_variabl == request.args.get('api'):
|
20 |
dey_db = globs.dey
|
|
|
38 |
# Запускаем асинхронный запрос в отдельном потоке
|
39 |
loop = asyncio.new_event_loop()
|
40 |
asyncio.set_event_loop(loop)
|
41 |
+
result = loop.run_until_complete(async_save_db(data))
|
42 |
loop.close()
|
43 |
|
44 |
+
err = 1 if result else 0
|
45 |
+
|
46 |
response_data = {
|
47 |
"eep_set": globs.eep_set,
|
48 |
"err": err
|