From 2d3288c3579a91f7ca5b5d4445494f3848be581a Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 2 May 2023 11:00:30 +0200 Subject: [PATCH] add main file --- __init__.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..99d26f2 --- /dev/null +++ b/__init__.py @@ -0,0 +1,52 @@ +# save this as app.py +from flask import Flask +from flask import request +from werkzeug.utils import secure_filename +from flask_mail import Mail, Message + +app = Flask(__name__) +app.config['MAIL_SERVER']='smtp-stax.alwaysdata.net' +app.config['MAIL_PORT'] = 587 +app.config['MAIL_USERNAME'] = 'backup@pokeranalytics.net' +app.config['MAIL_PASSWORD'] = 'StaxBackup****' +app.config['MAIL_USE_TLS'] = True + +mail = Mail(app) + +# EMAIL_HOST = 'smtp-stax.alwaysdata.net' +# EMAIL_PORT = 587 +# EMAIL_HOST_USER = 'backup@pokeranalytics.net' +# EMAIL_HOST_PASSWORD = 'StaxBackup****' +# EMAIL_USE_TLS = True +# DEFAULT_FROM_EMAIL = 'Poker Analytics Backup ' + + +@app.route('/') +def index(): + return 'Yeah! Install looks fine!' + +@app.route('/send', methods=['GET', 'POST']) +def sender(): + if request.method == 'POST': + # mail = request.args.get('mail', '') + recipient = request.form['recipient'] + file = request.files['file'] + return send_mail(recipient, file) + else: + return show_method_error(request.method) + +def send_mail(recipient, file): + + msg = Message('Poker Analytics Backup', sender = 'backup@pokeranalytics.net', recipients = [recipient]) + msg.body = "This is the backup" + + filename = secure_filename(file.filename) + msg.attach(filename, "text/csv", file.read()) + mail.send(msg) + + print(mail) + + return f'POST to {recipient}' + +def show_method_error(method): + return f'bad method:{method}'