Spaces:
Sleeping
Sleeping
DmitrMakeev
commited on
Commit
•
c3a8752
1
Parent(s):
54b5657
Update google_db.py
Browse files- google_db.py +21 -43
google_db.py
CHANGED
@@ -1,22 +1,11 @@
|
|
1 |
from flask import request, jsonify
|
2 |
import os
|
3 |
-
import
|
4 |
-
import
|
5 |
|
6 |
api_key = os.getenv('api_key')
|
7 |
-
base_url = os.getenv('base_url')
|
8 |
-
token = os.getenv('token')
|
9 |
-
list_id = os.getenv('list_id')
|
10 |
-
parameter_id = os.getenv('parameter_id')
|
11 |
-
|
12 |
-
async def async_add_user(data):
|
13 |
-
headers = {
|
14 |
-
'Authorization': f'Bearer {token}',
|
15 |
-
'Content-Type': 'application/json'
|
16 |
-
}
|
17 |
-
async with aiohttp.ClientSession() as session:
|
18 |
-
async with session.post(f"{base_url}lists/{list_id}/recipients", json=data, headers=headers) as response:
|
19 |
-
return response.status
|
20 |
|
21 |
def add_user():
|
22 |
err = 0
|
@@ -26,45 +15,34 @@ def add_user():
|
|
26 |
names = globs.name
|
27 |
emails = globs.email
|
28 |
phones = globs.phone
|
|
|
29 |
pr1s = globs.pr1
|
30 |
pr2s = globs.pr2
|
31 |
-
pr3s = globs.pr3
|
32 |
-
grups_id = globs.grup_id
|
33 |
|
34 |
# Создаем данные для отправки
|
35 |
data = {
|
|
|
36 |
'email': emails,
|
37 |
'values': [
|
38 |
-
{
|
39 |
-
|
40 |
-
|
41 |
-
}
|
42 |
-
{
|
43 |
-
'value': phones,
|
44 |
-
'parameter_id': parameter_id + 1 # Предполагаем, что есть уникальный ID для каждого параметра
|
45 |
-
},
|
46 |
-
{
|
47 |
-
'value': pr1s,
|
48 |
-
'parameter_id': parameter_id + 2
|
49 |
-
},
|
50 |
-
{
|
51 |
-
'value': pr2s,
|
52 |
-
'parameter_id': parameter_id + 3
|
53 |
-
},
|
54 |
-
{
|
55 |
-
'value': pr3s,
|
56 |
-
'parameter_id': parameter_id + 4
|
57 |
-
}
|
58 |
]
|
59 |
}
|
60 |
|
61 |
-
#
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
66 |
|
67 |
-
|
|
|
68 |
|
69 |
response_data = {
|
70 |
"status": "success" if err == 1 else "error",
|
|
|
1 |
from flask import request, jsonify
|
2 |
import os
|
3 |
+
import requests
|
4 |
+
import globs
|
5 |
|
6 |
api_key = os.getenv('api_key')
|
7 |
+
base_url = os.getenv('base_url') # URL сервера, например, 'https://api.notisend.ru/v1/email/'
|
8 |
+
token = os.getenv('token') # Ваш токен
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def add_user():
|
11 |
err = 0
|
|
|
15 |
names = globs.name
|
16 |
emails = globs.email
|
17 |
phones = globs.phone
|
18 |
+
grups_id = globs.grup_id # Это List ID
|
19 |
pr1s = globs.pr1
|
20 |
pr2s = globs.pr2
|
|
|
|
|
21 |
|
22 |
# Создаем данные для отправки
|
23 |
data = {
|
24 |
+
'list_id': grups_id,
|
25 |
'email': emails,
|
26 |
'values': [
|
27 |
+
{'value': names, 'parameter_id': 'nam1'},
|
28 |
+
{'value': phones, 'parameter_id': 'pho2'},
|
29 |
+
{'value': pr1s, 'parameter_id': 'pr13'},
|
30 |
+
{'value': pr2s, 'parameter_id': 'pr24'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
]
|
32 |
}
|
33 |
|
34 |
+
# Отправляем запрос
|
35 |
+
headers = {
|
36 |
+
'Authorization': f'Bearer {token}',
|
37 |
+
'Content-Type': 'application/json'
|
38 |
+
}
|
39 |
+
response = requests.post(f"{base_url}lists/{data['list_id']}/recipients", json=data, headers=headers)
|
40 |
+
|
41 |
+
# Сохраняем ответ от сервера в глобальную переменную
|
42 |
+
globs.server_response = response.text
|
43 |
|
44 |
+
# Проверяем статус ответа
|
45 |
+
err = 1 if response.status_code == 200 else 0
|
46 |
|
47 |
response_data = {
|
48 |
"status": "success" if err == 1 else "error",
|