psychologist / app.py
DmitrMakeev's picture
Update app.py
193a53d verified
raw
history blame
3.6 kB
from flask import Flask, request, render_template, jsonify
import requests
import os
app = Flask(__name__, template_folder="./")
base_url = os.getenv('base_url') # URL сервера
token = os.getenv('token') # Ваш токен
api_key = os.getenv('api_key') # Ваш
@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():
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')
pr4 = request.args.get('pr4')
pr4_id = request.args.get('pr4_id')
pr5 = request.args.get('pr5')
pr5_id = request.args.get('pr5_id')
data = {
"email": email,
"unconfirmed": False,
"values": [
{
"parameter_id": pr5_id,
"kind": "string",
"list_id": list_id,
"title": "pr5",
"value": pr5
},
{
"parameter_id": pr4_id,
"kind": "string",
"list_id": list_id,
"title": "pr4",
"value": pr4
},
{
"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)))