diff --git a/__init__.py b/__init__.py index eae6eff..99d26f2 100644 --- a/__init__.py +++ b/__init__.py @@ -1,12 +1,52 @@ +# save this as app.py from flask import Flask -from flask import render_template +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 hello_world(): - return render_template('hello.html') +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) -if __name__ == "__main__": - app.run(debug=True) + return f'POST to {recipient}' +def show_method_error(method): + return f'bad method:{method}' diff --git a/__init__.py.old b/__init__.py.old new file mode 100644 index 0000000..eae6eff --- /dev/null +++ b/__init__.py.old @@ -0,0 +1,12 @@ +from flask import Flask +from flask import render_template + +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return render_template('hello.html') + +if __name__ == "__main__": + app.run(debug=True) + diff --git a/app.py b/app.py deleted file mode 100644 index 99d26f2..0000000 --- a/app.py +++ /dev/null @@ -1,52 +0,0 @@ -# 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}'