DmitrMakeev commited on
Commit
6e5ec17
1 Parent(s): 548884c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -92
app.py CHANGED
@@ -1,98 +1,64 @@
1
- import flask
2
- from flask import request, jsonify, send_file
3
  import os
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
-
7
- from dotenv import load_dotenv
8
- import globs
9
- from flask import render_template
10
-
11
-
12
- from api_logic import api
13
-
14
-
15
-
16
- from google_db import save_db
17
-
18
- from my_sqlite import create_SQL
19
-
20
- load_dotenv()
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
- app = flask.Flask(__name__, template_folder="./")
32
- app.config['DEBUG'] = True
33
-
34
-
35
-
36
-
37
-
38
- @app.route("/")
39
- def index():
40
- return flask.render_template('index.html')
41
-
42
-
43
-
44
-
45
-
46
-
47
- @app.route('/online', methods=['GET'])
48
- def online():
49
- return render_template('online.html')
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
- @app.route('/settings', methods=['GET'])
61
- def settings():
62
- return render_template('settings.html')
63
-
64
-
65
-
66
-
67
-
68
-
69
- @app.route("/api", methods=['GET'])
70
- def handle_api():
71
- response = api()
72
- return response
73
-
74
-
75
- @app.route("/save_db", methods=['GET'])
76
- def handle_save_db():
77
- response = save_db()
78
- return response
79
-
80
-
81
- @app.route('/set_res')
82
- def set_res():
83
- globs.eep_set = 0
84
- return jsonify(value_set="reset")
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
 
97
 
98
 
 
1
+ from flask import Flask, request, jsonify
2
+ import requests
3
  import os
4
 
5
+ app = Flask(__name__)
6
+
7
+ api_key = os.getenv('api_key')
8
+ base_url = os.getenv('base_url') # URL сервера, например, 'https://api.notisend.ru/v1/email/'
9
+ 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')
18
+ email = request.args.get('email')
19
+ phone = request.args.get('phone')
20
+ grup_id = request.args.get('grup_id')
21
+ pr1 = request.args.get('pr1')
22
+ pr2 = request.args.get('pr2')
23
+
24
+ # Проверка значений переменных
25
+ if not all([name, email, phone, grup_id, pr1, pr2]):
26
+ return jsonify({"status": "error", "message": "Some required data is missing"}), 400
27
+
28
+ # Создаем данные для отправки
29
+ data = {
30
+ 'list_id': grup_id,
31
+ 'email': email,
32
+ 'values': [
33
+ {'value': name, 'parameter_id': 'name'},
34
+ {'value': phone, 'parameter_id': 'phone'},
35
+ {'value': pr1, 'parameter_id': 'utm1'},
36
+ {'value': pr2, 'parameter_id': 'utm2'}
37
+ ]
38
+ }
39
+
40
+ # Отправляем запрос
41
+ headers = {
42
+ 'Authorization': f'Bearer {token}',
43
+ 'Content-Type': 'application/json'
44
+ }
45
+ response = requests.post(f"{base_url}lists/{data['list_id']}/recipients", json=data, headers=headers)
46
+
47
+ # Проверяем статус ответа
48
+ if response.status_code == 200:
49
+ err = 1
50
+ message = "Operation completed successfully"
51
+ else:
52
+ message = f"Error: {response.status_code} - {response.text}"
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
59
 
60
+ if __name__ == '__main__':
61
+ app.run(host='0.0.0.0', port=5000)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
 
64