diff --git a/database.db b/database.db index 20e4a16..05ac929 100644 Binary files a/database.db and b/database.db differ diff --git a/flask_app.py b/flask_app.py index a886e7f..3a9bbe5 100644 --- a/flask_app.py +++ b/flask_app.py @@ -2,6 +2,8 @@ import sqlite3 import string +import requests +import os from flask import Flask, jsonify, request, render_template app = Flask(__name__) @@ -55,6 +57,17 @@ def wish_form(card_id): return render_template("send_wish.html", card=card) +def send_mail(email, sender, cardid, uid): + x = requests.post("https://api.mailgun.net/v3/sandboxa39931aba4ea43a885c240d815b0a2c2.mailgun.org/messages", + auth=("api", "9374b99615d0f43ff1e12995ef3c3317-8d821f0c-6df1ae28"), + files=[('inline[0]', ('card.jpg', open(f'{os.getcwd()}/static/{cardid}.jpg', mode='rb').read()))], + data={"from": "laurens@zappsters.pythonanywhere.com", + "to": [f"{email}"], + "subject": "Greeting card", + "text": f"You have been sent an AR greeting card from {sender}! The unique code for your personnel message i: " + uid}) + return x.text + + @app.route('/wish_insert', methods=['POST']) def wish_insert(): sender = request.form.get("sender") @@ -75,6 +88,9 @@ def wish_insert(): db_id = max_id + 1 uid = generate_uid(db_id) + if send_method == "email": + send_mail(send_destination,sender,card_id, uid) + card = cur.execute('SELECT * FROM card WHERE cardid' + '=' + str(card_id) + ';').fetchone() conn.execute( f"INSERT INTO wish (uid, sender, message, cardid) VALUES (\'{uid}\', \'{sender}\', \'{message}\', {card_id})")