DmitrMakeev
commited on
Commit
•
ca28115
1
Parent(s):
520e57d
Update app.py
Browse files
app.py
CHANGED
@@ -10,8 +10,6 @@ token = os.getenv('token') # Ваш токен
|
|
10 |
|
11 |
@app.route('/save_db', methods=['GET'])
|
12 |
def save_db():
|
13 |
-
err = 0
|
14 |
-
|
15 |
if request.args.get('api') == api_key:
|
16 |
# Получаем данные из запроса
|
17 |
name = request.args.get('name')
|
@@ -22,19 +20,20 @@ def save_db():
|
|
22 |
pr2 = request.args.get('pr2')
|
23 |
|
24 |
# Проверка значений переменных
|
25 |
-
if not all([
|
26 |
return jsonify({"status": "error", "message": "Some required data is missing"}), 400
|
27 |
|
28 |
# Создаем данные для отправки
|
29 |
data = {
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
{
|
34 |
-
{
|
35 |
-
{
|
36 |
-
{
|
37 |
-
]
|
|
|
38 |
}
|
39 |
|
40 |
# Отправляем запрос
|
@@ -42,17 +41,13 @@ def save_db():
|
|
42 |
'Authorization': f'Bearer {token}',
|
43 |
'Content-Type': 'application/json'
|
44 |
}
|
45 |
-
response = requests.post(f"{base_url}lists/{
|
46 |
|
47 |
# Проверяем статус ответа
|
48 |
if response.status_code == 200:
|
49 |
-
|
50 |
-
message = "Operation completed successfully"
|
51 |
else:
|
52 |
-
message
|
53 |
-
err = 0
|
54 |
-
|
55 |
-
return jsonify({"status": "success" if err == 1 else "error", "message": message}), 200 if err == 1 else 400
|
56 |
|
57 |
else:
|
58 |
return jsonify({"status": "error", "message": "Invalid API key"}), 401
|
@@ -69,13 +64,6 @@ def save_db():
|
|
69 |
|
70 |
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
|
80 |
if __name__ == '__main__':
|
81 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
|
|
10 |
|
11 |
@app.route('/save_db', methods=['GET'])
|
12 |
def save_db():
|
|
|
|
|
13 |
if request.args.get('api') == api_key:
|
14 |
# Получаем данные из запроса
|
15 |
name = request.args.get('name')
|
|
|
20 |
pr2 = request.args.get('pr2')
|
21 |
|
22 |
# Проверка значений переменных
|
23 |
+
if not all([email, name, phone, grup_id, pr1, pr2]):
|
24 |
return jsonify({"status": "error", "message": "Some required data is missing"}), 400
|
25 |
|
26 |
# Создаем данные для отправки
|
27 |
data = {
|
28 |
+
"email": email,
|
29 |
+
"unconfirmed": True, # Создаем неподтвержденного получателя
|
30 |
+
"values": [
|
31 |
+
{"parameter_id": "name", "value": name},
|
32 |
+
{"parameter_id": "phone", "value": phone},
|
33 |
+
{"parameter_id": "utm1", "value": pr1},
|
34 |
+
{"parameter_id": "utm2", "value": pr2}
|
35 |
+
],
|
36 |
+
"tags": ["buyer", "regular customer"] # Пример тегов
|
37 |
}
|
38 |
|
39 |
# Отправляем запрос
|
|
|
41 |
'Authorization': f'Bearer {token}',
|
42 |
'Content-Type': 'application/json'
|
43 |
}
|
44 |
+
response = requests.post(f"{base_url}lists/{grup_id}/recipients", json=data, headers=headers)
|
45 |
|
46 |
# Проверяем статус ответа
|
47 |
if response.status_code == 200:
|
48 |
+
return jsonify({"status": "success", "message": "Recipient created successfully"}), 200
|
|
|
49 |
else:
|
50 |
+
return jsonify({"status": "error", "message": f"Error: {response.status_code} - {response.text}"}), 400
|
|
|
|
|
|
|
51 |
|
52 |
else:
|
53 |
return jsonify({"status": "error", "message": "Invalid API key"}), 401
|
|
|
64 |
|
65 |
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
if __name__ == '__main__':
|
69 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|