-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
92 lines (69 loc) · 2.45 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import json
import os
from dotenv import load_dotenv
from flask import Flask, flash, redirect, render_template, request
from flask_mail import Mail, Message
load_dotenv()
app = Flask(__name__)
app.secret_key = "secret"
mail_settings = {
"MAIL_SERVER": "smtp.gmail.com",
"MAIL_PORT": 465,
"MAIL_USE_TLS": False,
"MAIL_USE_SSL": True,
"MAIL_USERNAME": os.environ.get("MAIL"),
"MAIL_PASSWORD": os.environ.get("PASSWORD"),
}
app.config.update(mail_settings)
mail = Mail(app)
class Contato:
def __init__(self, nome, email, mensagem):
self.nome = nome
self.email = email
self.mensagem = mensagem
@app.route("/")
def index():
skills_file = os.path.join(app.root_path, "content", "skills.json")
articles_file = os.path.join(app.root_path, "content", "articles.json")
education_file = os.path.join(app.root_path, "content", "education.json")
experiences_file = os.path.join(app.root_path, "content", "experiences.json")
projects_file = os.path.join(app.root_path, "content", "projects.json")
# Abrir e ler o arquivo skills.json
with open(skills_file, "r") as f:
skills = json.load(f)
with open(articles_file, "r") as f:
articles = json.load(f)
with open(education_file, "r") as f:
educations = json.load(f)
with open(experiences_file, "r") as f:
experiences = json.load(f)
with open(projects_file, "r") as f:
projects = json.load(f)
return render_template(
"index.html",
data_skills=skills,
data_articles=articles,
data_educations=educations,
data_experiences=experiences,
data_projects=projects,
)
@app.route("/send", methods=["GET", "POST"])
def send():
if request.method == "POST":
formContato = Contato(
request.form["nome"], request.form["email"], request.form["mensagem"]
)
msg = Message(
subject=f"{formContato.nome} te enviou uma mensagem",
sender=app.config.get("MAIL_USERNAME"),
recipients=[app.config.get("MAIL_USERNAME")],
body=f"""De: {formContato.nome}
E-mail: {formContato.email}
Mensagem: {formContato.mensagem}
""",
)
mail.send(msg)
flash("Mensagem enviada com sucesso!", "success")
return redirect("/")
if __name__ == "__main__":
app.run(port=5001, debug=True)