Skip to content

Commit

Permalink
fe
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammedHamioui committed May 30, 2022
2 parents 9111a7d + 2502544 commit 916dab2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Binary file modified database.db
Binary file not shown.
16 changes: 16 additions & 0 deletions flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import sqlite3
import string

import requests
import os
from flask import Flask, jsonify, request, render_template

app = Flask(__name__)
Expand Down Expand Up @@ -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": "[email protected]",
"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")
Expand All @@ -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})")
Expand Down

0 comments on commit 916dab2

Please sign in to comment.