-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
172 lines (125 loc) · 5.67 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
from flask import Flask,render_template,flash, redirect,url_for,session,request
from flask_sqlalchemy import SQLAlchemy
import smtplib,time
import urllib.request
import urllib.parse
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
db = SQLAlchemy(app)
class host(db.Model):
id = db.Column(db.Integer, primary_key=True)
husername = db.Column(db.String(80))
hemail = db.Column(db.String(120))
userphone = db.Column(db.String(80))
class visitor(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80))
email = db.Column(db.String(120))
visitorphone = db.Column(db.String(120))
checkin = db.Column(db.String(120))
def host_send_email(m,n,o,p,q):
# creates SMTP session
s = smtplib.SMTP('smtp.gmail.com',587)
# start TLS for security
s.starttls()
# Authentication
s.login("innovaccersummergeeks@gmail.com", "testing@123")
# message to be sent
text = "Hi Host,\n Visitor Name:\t"+ m +"\n Visitor Email:\t"+ n +"\n Visitor Phone\t"+ o+"\n Checkin Time:\t"+ p+"IST"+"\n visitor had just check in"
subject = "Visitor has just checked in"
message = 'Subject: {}\n\n{}'.format(subject, text)
# sending the mail
s.sendmail("innovaccersummergeeks@gmail.com", q, message)
# terminating the session
s.quit()
def visitor_send_email(a,b,c,d,e,f):
# creates SMTP session
s = smtplib.SMTP('smtp.gmail.com',587)
# start TLS for security
s.starttls()
# Authentication
s.login("innovaccersummergeeks@gmail.com", "testing@123")
#t = time.localtime()
#current_time = time.strftime("%H:%M:%S", t)
# message to be sent
text = "Thank you Visitor for visiting us,\n Visitor Name:\t"+ a +"\n Visitor Phone:\t"+ c +"\n Check-in Time:\t"+ d+"IST"+"\n Check-out Time:\t"+ e +"\n Host Name:\t"+ f + "\nAddress : Summergeeks by innovaccer"
subject = "Thank you Visiting us"
message = 'Subject: {}\n\n{}'.format(subject, text)
# sending the mail
s.sendmail("innovaccersummergeeks@gmail.com", b, message)
# terminating the session
s.quit()
def sendSMS(apikey, numbers, sender, message):
data = urllib.parse.urlencode({'apikey': '3LVJW9iNFVc-EaMh9LZLGuogPU33ec2HNPB3cr7oDV', 'numbers': numbers,'message':message,'sender':'TXTLCL'})
data = data.encode('utf-8')
request = urllib.request.Request("https://api.textlocal.in/send/?")
f = urllib.request.urlopen(request, data)
fr = f.read()
return(fr)
#resp = sendSMS('apikey', '919149189644','Jims Autos', 'This is your message')
@app.route("/")
@app.route("/index",methods=["GET","POST"])
def index():
return render_template("index.html")
@app.route("/host", methods=["GET", "POST"])
def hostpage():
if request.method == "POST":
hname = request.form['name']
hemail = request.form['email']
hphonenumber = request.form['phonenumber']
hregister = host(husername = hname, hemail = hemail, userphone = hphonenumber)
db.session.add(hregister)
db.session.commit()
return redirect(url_for("hostthank"))
return render_template("host.html")
@app.route("/hostthank", methods=["GET", "POST"])
def hostthank():
return render_template("hostthank.html")
@app.route("/hostcheck")
def hostcheck():
hrecords = host.query.order_by(host.id.desc()).first()
host_email = hrecords.__dict__['hemail']
host_phone = hrecords.__dict__['userphone']
vrecord = visitor.query.order_by(visitor.id.desc()).first()
visitor_names = vrecord.__dict__['username']
visitor_emails = vrecord.__dict__['email']
visitor_phones = vrecord.__dict__['visitorphone']
visitor_checkins= vrecord.__dict__['checkin']
host_send_email(visitor_names,visitor_emails,visitor_phones,visitor_checkins,host_email)
sms_mes = "Name:" + " "+ visitor_names + "\nEmail:" + visitor_emails + "\nPhone:" + visitor_phones + "\nCheckin:" + visitor_checkins
resp = sendSMS('apikey', host_phone ,'Innovaccer', sms_mes)
print(resp) # it will give balance sms
return render_template("hostcheck.html")
@app.route("/visitoremail" , methods=["GET", "POST"])
def visitoremail():
if request.method == "POST":
vrecords = visitor.query.order_by(visitor.id.desc()).first()
visitor_name = vrecords.__dict__['username']
visitor_email = vrecords.__dict__['email']
visitor_phone = vrecords.__dict__['visitorphone']
visitor_checkin = vrecords.__dict__['checkin']
vt = time.localtime()
visitor_checkout = time.strftime("%H:%M:%S", vt)
hrecord = host.query.order_by(host.id.desc()).first()
hostnames = hrecord.__dict__['husername']
#print(hrecord)
visitor_send_email(visitor_name,visitor_email,visitor_phone,visitor_checkin,visitor_checkout,hostnames)
return render_template("thankvisitor.html")
@app.route("/visitorinfo", methods=["GET", "POST"])
def visitorinfo():
if request.method == "POST":
firstname = request.form['first-name']
lastname = request.form['last-name']
vname = firstname+" " +lastname
visemail = request.form['vemail']
visphone = request.form['vphone']
vist = time.localtime()
visitor_checkin = time.strftime("%H:%M:%S", vist)
vregister = visitor(username = vname, email = visemail, visitorphone = visphone, checkin = visitor_checkin)
db.session.add(vregister)
db.session.commit()
return redirect(url_for("hostcheck"))
return render_template("visitor.html")
if __name__ == "__main__":
db.create_all()
app.run(debug=True)