|
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'): |
|
names = globsname |
|
emails = globs.email |
|
phones = globs.phone |
|
pr1s = globs.pr1 |
|
pr2s = globs.pr2 |
|
pr3s = globs.pr3 |
|
pr4s = globs.pr4 |
|
pr5s = globs.pr5 |
|
pr6s = globs.pr6 |
|
|
|
|
|
data = f"action=addData&names={names}&emails={emails}&phones={phones}&pr1s={pr1s}&pr2s={pr2s}&pr3s={pr3s}" |
|
|
|
|
|
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) |