|
import flask |
|
from flask import request, jsonify, send_file |
|
import os |
|
|
|
import asyncio |
|
import aiohttp |
|
|
|
from dotenv import load_dotenv |
|
import globs |
|
from flask import render_template |
|
|
|
|
|
|
|
|
|
load_dotenv() |
|
|
|
|
|
app = Flask(__name__) |
|
|
|
base_url = os.getenv('base_url') |
|
token = os.getenv('token') |
|
|
|
|
|
|
|
|
|
@app.route('/grups', methods=['GET']) |
|
def grups(): |
|
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 |
|
|
|
|
|
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') |
|
|
|
|
|
data = { |
|
"email": email, |
|
"unconfirmed": False |
|
} |
|
|
|
|
|
headers = { |
|
'Authorization': f'Bearer {token}', |
|
'Content-Type': 'application/json' |
|
} |
|
response = requests.post(f"{base_url}/email/lists/{grup_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))) |