|
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') |
|
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))) |