finally created a server and API
This commit is contained in:
parent
6d080ca45d
commit
5bf0eb08af
35
main.py
35
main.py
@ -3,15 +3,14 @@ import random
|
|||||||
import ssl
|
import ssl
|
||||||
import smtplib
|
import smtplib
|
||||||
|
|
||||||
|
from flask import Flask, jsonify, request
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.mime.image import MIMEImage
|
from email.mime.image import MIMEImage
|
||||||
|
|
||||||
mail_sender = "norman25.projects2@gmail.com"
|
app = Flask(__name__)
|
||||||
mail_password = os.environ.get("EMAIL_PASSWORD_2")
|
|
||||||
mail_receiver = "norman25.na@gmail.com"
|
|
||||||
|
|
||||||
def add_textimg(text):
|
def add_textimg(text):
|
||||||
img = Image.open("images/main/black-suit.png")
|
img = Image.open("images/main/black-suit.png")
|
||||||
@ -25,8 +24,21 @@ def add_textimg(text):
|
|||||||
img.save("images/output/pos.png")
|
img.save("images/output/pos.png")
|
||||||
img.close()
|
img.close()
|
||||||
|
|
||||||
|
@app.route('/hello', methods=['GET'])
|
||||||
|
def hello():
|
||||||
|
return "Hello"
|
||||||
|
|
||||||
|
@app.route('/send-otp', methods=['POST'])
|
||||||
def send_email():
|
def send_email():
|
||||||
|
mail_sender = "norman25.projects2@gmail.com"
|
||||||
|
mail_password = os.environ.get("EMAIL_PASSWORD_2")
|
||||||
|
mail_receiver = request.args.get('email')
|
||||||
|
|
||||||
|
if mail_receiver is None:
|
||||||
|
return jsonify({
|
||||||
|
"error": "You must include an email address param query to send to email"
|
||||||
|
}), 400
|
||||||
|
|
||||||
try:
|
try:
|
||||||
randis = random.randint(1000, 9999)
|
randis = random.randint(1000, 9999)
|
||||||
|
|
||||||
@ -53,8 +65,23 @@ def send_email():
|
|||||||
with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
|
with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
|
||||||
smtp.login(mail_sender, mail_password)
|
smtp.login(mail_sender, mail_password)
|
||||||
smtp.sendmail(mail_sender, mail_receiver, zmail.as_string())
|
smtp.sendmail(mail_sender, mail_receiver, zmail.as_string())
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"message": "Success sending email",
|
||||||
|
"email": {
|
||||||
|
"sender": mail_sender,
|
||||||
|
"receiver": mail_receiver,
|
||||||
|
"subject": subject,
|
||||||
|
"body": msg
|
||||||
|
}
|
||||||
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Failed to send a email")
|
print("Failed to send a email")
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
|
||||||
send_email()
|
return jsonify({
|
||||||
|
"error": str(e)
|
||||||
|
}), 400
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True)
|
Loading…
x
Reference in New Issue
Block a user