File size: 2,287 Bytes
6e5ec17 e9edc80 3ea419a 6e5ec17 3537db9 6e5ec17 4595fee 2923221 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 |
from flask import Flask, request, jsonify
import requests
import os
app = Flask(__name__)
api_key = os.getenv('api_key')
base_url = os.getenv('base_url') # URL сервера, например, 'https://api.notisend.ru/v1/email/'
token = os.getenv('token') # Ваш токен
@app.route('/save_db', methods=['GET'])
def save_db():
err = 0
if request.args.get('api') == api_key:
# Получаем данные из запроса
name = request.args.get('name')
email = request.args.get('email')
phone = request.args.get('phone')
grup_id = request.args.get('grup_id')
pr1 = request.args.get('pr1')
pr2 = request.args.get('pr2')
# Проверка значений переменных
if not all([name, email, phone, grup_id, pr1, pr2]):
return jsonify({"status": "error", "message": "Some required data is missing"}), 400
# Создаем данные для отправки
data = {
'list_id': grup_id,
'email': email,
'values': [
{'value': name, 'parameter_id': 'name'},
{'value': phone, 'parameter_id': 'phone'},
{'value': pr1, 'parameter_id': 'utm1'},
{'value': pr2, 'parameter_id': 'utm2'}
]
}
# Отправляем запрос
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
response = requests.post(f"{base_url}lists/{data['list_id']}/recipients", json=data, headers=headers)
# Проверяем статус ответа
if response.status_code == 200:
err = 1
message = "Operation completed successfully"
else:
message = f"Error: {response.status_code} - {response.text}"
err = 0
return jsonify({"status": "success" if err == 1 else "error", "message": message}), 200 if err == 1 else 400
else:
return jsonify({"status": "error", "message": "Invalid API key"}), 401
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860))) |