DmitrMakeev commited on
Commit
4818e9b
1 Parent(s): 95f07ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -41
app.py CHANGED
@@ -1,4 +1,5 @@
1
  from flask import Flask, request, jsonify
 
2
  import requests
3
  import os
4
 
@@ -10,47 +11,36 @@ token = os.getenv('token') # Ваш токен
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')
16
- email = request.args.get('email')
17
- phone = request.args.get('phone')
18
- grup_id = request.args.get('grup_id')
19
- pr1 = request.args.get('pr1')
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
- # Отправляем запрос
40
- headers = {
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
54
 
55
 
56
 
 
1
  from flask import Flask, request, jsonify
2
+ from flask import Flask, request
3
  import requests
4
  import os
5
 
 
11
 
12
  @app.route('/save_db', methods=['GET'])
13
  def save_db():
14
+ # Получаем данные из запроса
15
+ name = request.args.get('name')
16
+ email = request.args.get('email')
17
+ phone = request.args.get('phone')
18
+ grup_id = request.args.get('grup_id')
19
+ pr1 = request.args.get('pr1')
20
+ pr2 = request.args.get('pr2')
21
+
22
+ # Создаем данные для отправки
23
+ data = {
24
+ "email": email,
25
+ "unconfirmed": True, # Создаем неподтвержденного получателя
26
+ "values": [
27
+ {"parameter_id": "name", "value": name},
28
+ {"parameter_id": "phone", "value": phone},
29
+ {"parameter_id": "utm1", "value": pr1},
30
+ {"parameter_id": "utm2", "value": pr2}
31
+ ],
32
+ "tags": ["buyer", "regular customer"] # Пример тегов
33
+ }
34
+
35
+ # Отправляем запрос
36
+ headers = {
37
+ 'Authorization': f'Bearer {token}',
38
+ 'Content-Type': 'application/json'
39
+ }
40
+ response = requests.post(f"{base_url}lists/{grup_id}/recipients", json=data, headers=headers)
41
+
42
+ # Возвращаем текст ответа сервера
43
+ return response.text
 
 
 
 
 
 
 
 
 
 
 
44
 
45
 
46