-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.py
64 lines (52 loc) · 2.64 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
from flask import Flask, render_template, flash, request, redirect, url_for, session, send_file
from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField
import sendgrid
import os
users = 0
class ContactForm(Form):
name = TextField('Full Name', validators=[validators.DataRequired()], render_kw={"placeholder": "Name"})
email = TextField('Email ID', validators=[validators.DataRequired()], render_kw={"placeholder": "Email"} )
phone = TextField('Phone Number', validators=[validators.DataRequired()], render_kw={"placeholder": "Phone Number"})
foi = TextField('Field Of Interest', validators=[validators.DataRequired()], render_kw={"placeholder": "Field Of Interest"})
def send_mail(users, name, email, ph_num, field):
sg = sendgrid.SendGridAPIClient(apikey = os.environ.get("SG_API_KEY"))
from_email = sendgrid.helpers.mail.Email("[email protected]", name="Widhya Org")
#print(subject_given.split("-")[0])
to_email = sendgrid.helpers.mail.Email("[email protected]")
#print(to_email)
subject = "Subscribers List "
mail_content = "Name : <b>%s</b> <br>Email ID : <b>%s</b> <br>Number : <b>%s</b> <br>Field Of Interest : <b>%s</b> <br>"%(name, email, ph_num, field)
content = sendgrid.helpers.mail.Content("text/html", "<html><body><p>Thanks for actually using this particular thingy. I hope you're doing good! Thank those who actually agreed to use this particular website.</p> <br> <pre>%s</pre></body></html>"%(mail_content))
mail = sendgrid.helpers.mail.Mail(from_email, subject, to_email, content)
response = sg.client.mail.send.post(request_body=mail.get())
return response
DEBUG = True
app = Flask(__name__) #initialising flask
app.config.from_object(__name__) #configuring flask
app.config['SECRET_KEY'] = '7d441f27d441f27567d441f2b6176a'
app = Flask(__name__)
@app.route("/", methods=['GET', 'POST'])
def index():
form = ContactForm(request.form)
if(request.method == 'POST'):
if(form.validate()):
global users
users += 1
response = send_mail(users, request.form['name'],request.form['email'],request.form['phone'],request.form['foi'])
return redirect(url_for("index"))
return render_template("index.html", form=form)
@app.route("/rahul", methods=['GET', 'POST'])
def Rahul_Widhya_VisitingCard():
return send_file("docs/Rahul_VisitingCard.pdf")
@app.route("/rishabh", methods=['GET', 'POST'])
def Rishabh_Widhya_VisitingCard():
return send_file("docs/Rishabh_VisitingCard.pdf")
'''@app.errorhandler(404)
def not_found(e):
return render_template("404.html")
'''
@app.errorhandler(500)
def application_error(e):
return 'Sorry, unexpected error: {}'.format(e), 500
if(__name__ == "__main__"):
app.run(debug=True)