File size: 3,228 Bytes
7552ee6
ff0ece9
16c32c6
c8e4ab5
58cae0c
6e5ec17
ff0ece9
6e5ec17
 
62f6da6
16cbbfb
9368cf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e5ec17
 
7c09dcc
 
 
ff0ece9
7c09dcc
 
4818e9b
7c09dcc
 
4818e9b
7c09dcc
4818e9b
7c09dcc
4818e9b
7c09dcc
 
 
304b5eb
4818e9b
7c09dcc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4818e9b
 
 
 
 
 
7c09dcc
4818e9b
967e410
e61a89f
 
 
 
 
967e410
 
4595fee
f18f04b
2923221
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from flask import Flask, request, render_template, jsonify
import requests
import os

app = Flask(__name__, template_folder="./")

base_url = os.getenv('base_url')  # URL сервера, например, 'https://api.notisend.ru/v1/email/'
token = os.getenv('token')  # Ваш токен

@app.route('/grups', methods=['GET'])
def grup():
    return render_template('grups.html')

@app.route('/send_request', methods=['POST'])
def send_request():
    api_token = request.form.get('api_token')
    group_id = request.form.get('group_id')
    url = f"https://api.notisend.ru/v1/email/lists/{group_id}/parameters"
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {api_token}'
    }
    response = requests.get(url, headers=headers)
    data = response.json()
    return jsonify(data)

@app.route('/save_db', methods=['GET'])
def save_db():
    api_key_from_request = request.args.get('api_key')
    if api_key_from_request != api_key:
        return jsonify({'error': '666', 'message': 'Invalid api_key'}), 403

    show_params = False
    list_id = request.args.get('list_id')
    name = request.args.get('name')
    name_id = request.args.get('name_id')    
    email = request.args.get('email')  
    phone = request.args.get('phone')
    phone_id = request.args.get('phone_id')
    pr1 = request.args.get('pr1')
    pr1_id = request.args.get('pr1_id')   
    pr2 = request.args.get('pr2')
    pr2_id = request.args.get('pr2_id')    
    pr3 = request.args.get('pr3')
    pr3_id = request.args.get('pr3_id')    
    data = {
        "email": email,
        "unconfirmed": False,
        "values": [
            {
                "parameter_id": pr3_id,
                "kind": "string",
                "list_id": list_id,
                "title": "pr3",
                "value": pr3
            },
            {
                "parameter_id": pr2_id,
                "kind": "string",
                "list_id": list_id,
                "title": "pr2",
                "value": pr2
            },
            {
                "parameter_id": pr1_id,
                "kind": "string",
                "list_id": list_id,
                "title": "pr1",
                "value": pr1
            },
            {
                "parameter_id": phone_id,
                "kind": "string",
                "list_id": list_id,
                "title": "phone",
                "value": phone
            },
            {
                "parameter_id": name_id,
                "kind": "string",
                "list_id": list_id,
                "title": "name",
                "value": name
            }
        ]
    }

    headers = {
        'Authorization': f'Bearer {token}',
        'Content-Type': 'application/json'
    }
    response = requests.post(f"{base_url}/email/lists/{list_id}/recipients", json=data, headers=headers)

    if show_params:
        system_vars = {
            'base_url': base_url,
            'token': token
        }
        return jsonify({'system_variables': system_vars, 'request_parameters': request.args})
    else:
        return response.text

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))