-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (44 loc) · 1.61 KB
/
main.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
from flask import Flask, render_template, request
import requests
import smtplib
app = Flask(__name__)
response = requests.get("https://api.npoint.io/e810d59e6ed4856aa62a").json()
MY_EMAIL = "[email protected]"
PASSWORD = "Funix@2022"
@app.route("/")
def home():
return render_template("index.html", data=response)
@app.route("/about")
def about():
return render_template("about.html")
@app.route("/contact", methods=["POST", "GET"])
def contact():
msg = "Contact Me"
if request.method == 'POST':
name = request.form["username"]
email = request.form["email"]
phone = request.form["phone"]
message = request.form["message"]
email_msg = f"From: {name}\n Address: {email}\n Phone number: {phone}\n Message: {message}"
with smtplib.SMTP("smtp.gmail.com", port=587) as connection:
connection.ehlo()
connection.starttls()
connection.login(user=MY_EMAIL, password=PASSWORD)
connection.sendmail(
from_addr=MY_EMAIL,
to_addrs="[email protected]",
msg=f"Subject:You have new message\n\n{email_msg}"
)
msg = "Successfully sent message"
return render_template("contact.html", send_msg=msg)
@app.route("/post/<int:blog_id>")
def blog_post(blog_id):
blog = None
for item in response:
if item["id"] == blog_id:
blog = item
break
print(blog_id)
return render_template("post.html", title=blog["title"], subtitle=blog["subtitle"], body=blog["body"])
if __name__ == "__main__":
app.run(debug=True)