Spaces:
Sleeping
Sleeping
DmitrMakeev
commited on
Commit
•
58cae0c
1
Parent(s):
f4e0c89
Update app.py
Browse files
app.py
CHANGED
@@ -2,23 +2,15 @@ from flask import Flask, request, render_template, jsonify
|
|
2 |
import requests
|
3 |
import os
|
4 |
|
5 |
-
app =
|
6 |
-
|
7 |
|
8 |
base_url = os.getenv('base_url') # URL сервера, например, 'https://api.notisend.ru/v1/email/'
|
9 |
token = os.getenv('token') # Ваш токен
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
@app.route('/grups', methods=['GET'])
|
15 |
def grup():
|
16 |
return render_template('grups.html')
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
@app.route('/send_request', methods=['POST'])
|
23 |
def send_request():
|
24 |
api_token = request.form.get('api_token')
|
@@ -32,22 +24,10 @@ def send_request():
|
|
32 |
data = response.json()
|
33 |
return jsonify(data)
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
@app.route('/save_db', methods=['GET'])
|
46 |
def save_db():
|
47 |
-
# Переменная для переключения между возвратом параметров и ответа сервера
|
48 |
show_params = False
|
49 |
|
50 |
-
# Получаем данные из запроса
|
51 |
name = request.args.get('name')
|
52 |
email = request.args.get('email')
|
53 |
phone = request.args.get('phone')
|
@@ -55,22 +35,18 @@ def save_db():
|
|
55 |
pr1 = request.args.get('pr1')
|
56 |
pr2 = request.args.get('pr2')
|
57 |
|
58 |
-
# Создаем данные для отправки
|
59 |
data = {
|
60 |
"email": email,
|
61 |
"unconfirmed": False
|
62 |
}
|
63 |
|
64 |
-
# Отправляем запрос
|
65 |
headers = {
|
66 |
'Authorization': f'Bearer {token}',
|
67 |
'Content-Type': 'application/json'
|
68 |
}
|
69 |
response = requests.post(f"{base_url}/email/lists/{grup_id}/recipients", json=data, headers=headers)
|
70 |
|
71 |
-
# Возвращаем либо текст ответа сервера, либо входящие параметры запроса и системные переменные
|
72 |
if show_params:
|
73 |
-
# Собираем системные переменные и параметры запроса
|
74 |
system_vars = {
|
75 |
'base_url': base_url,
|
76 |
'token': token
|
|
|
2 |
import requests
|
3 |
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'])
|
11 |
def grup():
|
12 |
return render_template('grups.html')
|
13 |
|
|
|
|
|
|
|
|
|
14 |
@app.route('/send_request', methods=['POST'])
|
15 |
def send_request():
|
16 |
api_token = request.form.get('api_token')
|
|
|
24 |
data = response.json()
|
25 |
return jsonify(data)
|
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')
|
|
|
35 |
pr1 = request.args.get('pr1')
|
36 |
pr2 = request.args.get('pr2')
|
37 |
|
|
|
38 |
data = {
|
39 |
"email": email,
|
40 |
"unconfirmed": False
|
41 |
}
|
42 |
|
|
|
43 |
headers = {
|
44 |
'Authorization': f'Bearer {token}',
|
45 |
'Content-Type': 'application/json'
|
46 |
}
|
47 |
response = requests.post(f"{base_url}/email/lists/{grup_id}/recipients", json=data, headers=headers)
|
48 |
|
|
|
49 |
if show_params:
|
|
|
50 |
system_vars = {
|
51 |
'base_url': base_url,
|
52 |
'token': token
|