DmitrMakeev commited on
Commit
05035e7
·
verified ·
1 Parent(s): 7c09dcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -24
app.py CHANGED
@@ -4,7 +4,7 @@ import os
4
 
5
  app = Flask(__name__, template_folder="./")
6
 
7
- base_url = os.getenv('base_url') # URL сервера, например, 'https://api.notisend.ru/v1/email/'
8
  token = os.getenv('token') # Ваш токен
9
 
10
  @app.route('/grups', methods=['GET'])
@@ -26,59 +26,51 @@ def send_request():
26
 
27
  @app.route('/save_db', methods=['GET'])
28
  def save_db():
29
- api_key_from_request = request.args.get('api_key')
30
- if api_key_from_request != api_key:
31
- return jsonify({'error': '666', 'message': 'Invalid api_key'}), 403
32
-
33
  show_params = False
34
- list_id = request.args.get('list_id')
35
  name = request.args.get('name')
36
- name_id = request.args.get('name_id')
37
- email = request.args.get('email')
38
  phone = request.args.get('phone')
39
- phone_id = request.args.get('phone_id')
40
  pr1 = request.args.get('pr1')
41
- pr1_id = request.args.get('pr1_id')
42
  pr2 = request.args.get('pr2')
43
- pr2_id = request.args.get('pr2_id')
44
  pr3 = request.args.get('pr3')
45
- pr3_id = request.args.get('pr3_id')
46
  data = {
47
  "email": email,
48
  "unconfirmed": False,
49
  "values": [
50
  {
51
- "parameter_id": pr3_id,
52
  "kind": "string",
53
- "list_id": list_id,
54
  "title": "pr3",
55
  "value": pr3
56
  },
57
  {
58
- "parameter_id": pr2_id,
59
  "kind": "string",
60
- "list_id": list_id,
61
  "title": "pr2",
62
  "value": pr2
63
  },
64
  {
65
- "parameter_id": pr1_id,
66
  "kind": "string",
67
- "list_id": list_id,
68
  "title": "pr1",
69
  "value": pr1
70
  },
71
  {
72
- "parameter_id": phone_id,
73
  "kind": "string",
74
- "list_id": list_id,
75
  "title": "phone",
76
  "value": phone
77
  },
78
  {
79
- "parameter_id": name_id,
80
  "kind": "string",
81
- "list_id": list_id,
82
  "title": "name",
83
  "value": name
84
  }
@@ -89,7 +81,7 @@ def save_db():
89
  'Authorization': f'Bearer {token}',
90
  'Content-Type': 'application/json'
91
  }
92
- response = requests.post(f"{base_url}/email/lists/{list_id}/recipients", json=data, headers=headers)
93
 
94
  if show_params:
95
  system_vars = {
@@ -98,7 +90,7 @@ def save_db():
98
  }
99
  return jsonify({'system_variables': system_vars, 'request_parameters': request.args})
100
  else:
101
- return response.text
102
 
103
  if __name__ == '__main__':
104
  app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
 
4
 
5
  app = Flask(__name__, template_folder="./")
6
 
7
+ base_url = os.getenv('base_url') # URL сервера
8
  token = os.getenv('token') # Ваш токен
9
 
10
  @app.route('/grups', methods=['GET'])
 
26
 
27
  @app.route('/save_db', methods=['GET'])
28
  def save_db():
 
 
 
 
29
  show_params = False
30
+
31
  name = request.args.get('name')
32
+ email = request.args.get('email')
 
33
  phone = request.args.get('phone')
34
+ grup_id = request.args.get('grup_id')
35
  pr1 = request.args.get('pr1')
 
36
  pr2 = request.args.get('pr2')
 
37
  pr3 = request.args.get('pr3')
 
38
  data = {
39
  "email": email,
40
  "unconfirmed": False,
41
  "values": [
42
  {
43
+ "parameter_id": 390240,
44
  "kind": "string",
45
+ "list_id": 557103,
46
  "title": "pr3",
47
  "value": pr3
48
  },
49
  {
50
+ "parameter_id": 390239,
51
  "kind": "string",
52
+ "list_id": 557103,
53
  "title": "pr2",
54
  "value": pr2
55
  },
56
  {
57
+ "parameter_id": 390238,
58
  "kind": "string",
59
+ "list_id": 557103,
60
  "title": "pr1",
61
  "value": pr1
62
  },
63
  {
64
+ "parameter_id": 390237,
65
  "kind": "string",
66
+ "list_id": 557103,
67
  "title": "phone",
68
  "value": phone
69
  },
70
  {
71
+ "parameter_id": 390236,
72
  "kind": "string",
73
+ "list_id": 557103,
74
  "title": "name",
75
  "value": name
76
  }
 
81
  'Authorization': f'Bearer {token}',
82
  'Content-Type': 'application/json'
83
  }
84
+ response = requests.post(f"{base_url}/email/lists/{grup_id}/recipients", json=data, headers=headers)
85
 
86
  if show_params:
87
  system_vars = {
 
90
  }
91
  return jsonify({'system_variables': system_vars, 'request_parameters': request.args})
92
  else:
93
+ return jsonify(response.json()) # Возвращаем JSON-ответ от сервера
94
 
95
  if __name__ == '__main__':
96
  app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))