Skip to content

Commit 496db08

Browse files
committed
day 60
- Make POST Requests with Flask and HTML Forms
1 parent 98aaa1b commit 496db08

File tree

21 files changed

+11250
-7
lines changed

21 files changed

+11250
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
## 🏆 Advanced
6868
- [Day 59](https://github.com/a092devs/100-days-of-python/tree/master/day059) - Blog Capstone Project Part 2 - Adding Styling
69+
- [Day 60](https://github.com/a092devs/100-days-of-python/tree/master/day060) - Make POST Requests with Flask and HTML Forms
6970

7071
## ⚙ Tools and Technologies Covered
7172
- Python 3

day032/birthday_wisher/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
with open(f"letter_templates/letter_{random.randint(1, 3)}.txt") as letter:
2020
mail = letter.read()
2121
mail = mail.replace("[NAME]", name)
22-
with smtplib.SMTP("smtp.mail.yahoo.com", 587) as connection:
22+
with smtplib.SMTP("smtp.gmail.com", 587) as connection:
2323
connection.starttls()
2424
connection.login(email, password)
2525
connection.sendmail(from_addr=email,

day032/send_quotes/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
quote = random.choice(all_quotes)
1515

1616
# print(quote)
17-
with smtplib.SMTP("smtp.mail.yahoo.com", 587) as connection:
17+
with smtplib.SMTP("smtp.gmail.com", 587) as connection:
1818
connection.starttls()
1919
connection.login(email, password)
2020
connection.sendmail(from_addr=email,

day033/iss_overhead/main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
from dateutil.parser import isoparse
44
import time
55
import smtplib
6+
from os import environ
7+
from dotenv import load_dotenv
68

7-
FROM_EMAIL = "my_email_was_here"
8-
PASSWORD = "my_pass_was_here"
9+
load_dotenv('config.env', override=True)
10+
11+
FROM_EMAIL = environ.get("FROM_EMAIL")
12+
PASSWORD = environ.get("FROM_PASSWORD")
913
MY_LAT = 23.603900
1014
MY_LONG = 87.117700
1115

@@ -47,7 +51,7 @@ def is_night():
4751
while True:
4852
time.sleep(60)
4953
if is_iss_overhead() and is_night():
50-
with smtplib.SMTP("smtp.mail.yahoo.com", 587) as connection:
54+
with smtplib.SMTP("smtp.gmail.com", 587) as connection:
5155
connection.starttls()
5256
connection.login(FROM_EMAIL, PASSWORD)
5357
connection.sendmail(

day040/notification_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
BOT_TOKEN = environ.get("BOT_TOKEN")
99
CHAT_ID = environ.get("CHAT_ID")
10-
MAIL_PROVIDER_SMTP_ADDRESS = "smtp.mail.yahoo.com"
10+
MAIL_PROVIDER_SMTP_ADDRESS = "smtp.gmail.com"
1111
FROM_EMAIL = environ.get("FROM_EMAIL")
1212
FROM_PASSWORD = environ.get("FROM_PASSWORD")
1313

day047/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
exit()
4949

5050
if price < user_price:
51-
with smtplib.SMTP("smtp.mail.yahoo.com", 587) as connection:
51+
with smtplib.SMTP("smtp.gmail.com", 587) as connection:
5252
connection.starttls()
5353
connection.login(FROM_EMAIL, FROM_PASSWORD)
5454
connection.sendmail(from_addr=FROM_EMAIL,

day060/main.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import requests
2+
import smtplib
3+
from os import environ
4+
from dotenv import load_dotenv
5+
from flask import Flask, render_template, request
6+
7+
load_dotenv('config.env', override=True)
8+
9+
EMAIL = environ.get("FROM_EMAIL")
10+
PASSWORD = environ.get("FROM_PASSWORD")
11+
TO_EMAIL = environ.get("TO_EMAIL")
12+
13+
blog_url = "https://api.npoint.io/f62984d9b3959809e56a"
14+
blog_resp = requests.get(blog_url)
15+
all_posts = blog_resp.json()
16+
17+
app = Flask(__name__)
18+
19+
@app.route('/')
20+
def home():
21+
return render_template("index.html", posts=all_posts)
22+
23+
@app.route('/index.html')
24+
def index():
25+
return render_template("index.html", posts=all_posts)
26+
27+
@app.route('/about.html')
28+
def about():
29+
return render_template('about.html')
30+
31+
@app.route('/post/<int:p_id>')
32+
def post(p_id):
33+
return render_template('post.html', post=all_posts[int(p_id) - 1])
34+
35+
@app.route('/contact.html', methods=['GET', 'POST'])
36+
def contact():
37+
if request.method == 'POST':
38+
data = request.form
39+
name = (data['name'])
40+
email = (data['email'])
41+
phone = (data['phone'])
42+
message = (data['message'])
43+
with smtplib.SMTP('smtp.gmail.com', 587) as connection:
44+
connection.starttls()
45+
connection.login(user="EMAIL", password="PASSWORD")
46+
connection.sendmail(from_addr="EMAIL",
47+
to_addrs="EMAIL",
48+
msg=f"Subject:New Message Received!\n\nName: {name}\nEmail: {email}\nPhone: {phone}\nMessage: {message}")
49+
return render_template('contact.html', msg_sent=True)
50+
return render_template('contact.html', msg_sent=False)
51+
52+
@app.route('/post/<int:p_id>')
53+
def get_post(p_id):
54+
return render_template('post.html', post=all_posts[int(p_id) - 1])
55+
56+
if __name__ == "__main__":
57+
app.run(debug=True)

day060/static/assets/favicon.ico

22.9 KB
Binary file not shown.

day060/static/assets/img/about-bg.jpg

2.43 MB
Loading
489 KB
Loading

day060/static/assets/img/home-bg.jpg

984 KB
Loading

day060/static/assets/img/post-bg.jpg

1.72 MB
Loading
112 KB
Loading

0 commit comments

Comments
 (0)