Skip to content

Commit e7d08fa

Browse files
committed
Deleted files of Heroku master from Project9-Postgresql-Flask-App
1 parent 708b502 commit e7d08fa

25 files changed

+154
-1
lines changed

Project9-Postgresql-Flask-App

-1
This file was deleted.

Project9-PostgresqlFlaskApp/app.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from flask import Flask , render_template , request
2+
from flask_sqlalchemy import SQLAlchemy
3+
from send_email import send_email
4+
from sqlalchemy.sql import func
5+
6+
app =Flask(__name__)
7+
#app.config['SQLALCHEMY_DATABASE_URI']='postgresql://saharsh:saharsh@localhost/saharsh'
8+
app.config['SQLALCHEMY_DATABASE_URI']='postgres://ealjwezyboygbs:33a86d136be843dd9b44f3bab835ee293fe1cc570b4fdf1a8b4c5919d899160d@ec2-54-225-76-201.compute-1.amazonaws.com:5432/d6lq10srd6ftef?sslmode=require'
9+
db=SQLAlchemy(app)
10+
11+
class Data(db.Model):
12+
__tablename__="data"
13+
id=db.Column(db.Integer,primary_key=True)
14+
email_=db.Column(db.String(120),unique=True)
15+
height_=db.Column(db.Integer)
16+
17+
def __init__(self,email_,height_):
18+
self.email_=email_
19+
self.height_=height_
20+
21+
@app.route('/')
22+
def index():
23+
return render_template('index.html')
24+
25+
@app.route('/success',methods=['POST'])
26+
def success():
27+
if request.method=='POST':
28+
email=request.form['email_name']
29+
height=request.form['height_name']
30+
print(email,height)
31+
32+
if db.session.query(Data).filter(Data.email_==email).count()==0:
33+
34+
data=Data(email,height)
35+
db.session.add(data)
36+
db.session.commit()
37+
average_height=db.session.query(func.avg(Data.height_)).scalar()
38+
average_height=round(average_height,1)
39+
count=db.session.query(Data.height_).count()
40+
send_email(email,height,average_height,count)
41+
return render_template('success.html')
42+
return render_template('index.html',
43+
text="Seems like you already submitted.?")
44+
45+
if __name__=='__main__':
46+
app.debug=True
47+
app.run()
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from email.mime.text import MIMEText
2+
import smtplib
3+
4+
def send_email(email, height, average_height, count):
5+
from_email="[email protected]"
6+
from_password="apollo2274"
7+
to_email=email
8+
9+
subject="Height data"
10+
message="Hey there, your height is <strong>%s</strong>. <br> Average height of all is <strong>%s</strong> and that is calculated out of <strong>%s</strong> people. <br> Thanks!" % (height, average_height, count)
11+
12+
msg=MIMEText(message, 'html')
13+
msg['Subject']=subject
14+
msg['To']=to_email
15+
msg['From']=from_email
16+
17+
gmail=smtplib.SMTP('smtp.gmail.com',587)
18+
gmail.ehlo()
19+
gmail.starttls()
20+
gmail.login(from_email, from_password)
21+
gmail.send_message(msg)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
html, body {
2+
height: 100%;
3+
margin: 0;
4+
}
5+
6+
.container {
7+
margin: 0 auto;
8+
width: 100%;
9+
height: 100%;
10+
background-color: #006666;
11+
color: #e6ffff;
12+
overflow:hidden;
13+
text-align: center;
14+
}
15+
16+
.container h1 {
17+
font-family: Arial, sans-serif;
18+
font-size: 30px;
19+
color: #e6ffff;
20+
margin-top: 80px;
21+
}
22+
23+
.container form {
24+
margin: 20px;
25+
}
26+
27+
.container input {
28+
width: 350px;
29+
height: 15px;
30+
font-size: 15px;
31+
margin: 2px;
32+
padding: 20px;
33+
transition: all 0.2s ease-in-out;
34+
}
35+
36+
.container button {
37+
width:70px;
38+
height: 30px;
39+
background-color: steelblue;
40+
margin: 3px;
41+
}
42+
43+
.success-message {
44+
margin: 100px;
45+
}
46+
47+
.email {
48+
font-family: Arial, sans-serif;
49+
font-size: 15px;
50+
color: #ff9999;
51+
transition: all 0.2s ease-in-out;
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<title> Data Collector App</title>
4+
<head>
5+
<link href="../static/main.css" rel="stylesheet">
6+
</head>
7+
<body>
8+
<div class="container">
9+
<h1>Collecting height</h1>
10+
<h3>Please fill the entires to get population statistics on height</h3>
11+
12+
<div class="email"> {{text | safe}} </div>
13+
<form action="{{url_for('success')}}" method="POST">
14+
<input title="Your email will be safe with us" placeholder="Enter your email address" type="email" name="email_name" required> <br>
15+
<input title="Your data will be safe with us" placeholder="Enter your height in cm" type="number" min="50", max="300" name="height_name" required> <br>
16+
<button type="submit"> Submit </button>
17+
</form>
18+
</div>
19+
</body>
20+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<title> Data Collector App</title>
4+
<head>
5+
<link href="../static/main.css" rel="stylesheet">
6+
</head>
7+
<body>
8+
<div class="container">
9+
<p class="success-message"> Thank you for your submission! <br>
10+
You will receive an email with the survey results shortly.
11+
</p>
12+
</div>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)