-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
16 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": "[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") | ||
|
@@ -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})") | ||
|