-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflask_sqlite.py
209 lines (160 loc) · 5.15 KB
/
flask_sqlite.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#importing important libraries
from flask import Flask, render_template, request
import sqlite3 as sql
from flask import flash, redirect, session, abort
from datetime import date, datetime
app = Flask(__name__)
app.secret_key = "super secret key"
labels = [
'Apollo', 'Fortis', 'Max Health'
]
values = [
30,25,30
]
colors = [
"#F7464A", "#46BFBD", "#FDB45C"]
@app.route('/')
def home():
if not session.get('logged_in'):
return render_template('login.html')
else:
return render_template('home.html')
@app.route('/login', methods=['POST'])
def do_admin_login():
usr = request.form['username']
pwd = request.form['password']
conn = sql.connect("admin.db")
cur = conn.cursor()
cur.execute("SELECT password FROM doctors")
rows = cur.fetchall()
for row in rows:
pswd=row[0]
print(pswd)
conn.close()
#print(pswd,pwd)
if pwd==pswd:
session['logged_in'] = True
else:
flash('wrong password!')
return home()
@app.route("/logout")
def logout():
session['logged_in'] = False
return home()
@app.route('/plogin')
def phome():
if not session.get('logged_in'):
return render_template('login2.html')
else:
return plist()
@app.route('/login2', methods=['POST'])
def do_patient_login():
usr = request.form['username']
pwd = request.form['password']
conn = sql.connect("patient.db")
cur = conn.cursor()
cur.execute("SELECT password FROM patients where pid=?",(usr,))
rows = cur.fetchall()
for row in rows:
pswd=row[0]
print(pswd)
conn.close()
#print(pswd,pwd)
if pwd==pswd:
session['logged_in'] = usr
else:
flash('wrong password!')
return phome()
@app.route('/enternew')
def new_student():
if not session.get('logged_in'):
return render_template('login.html')
return render_template('student.html')
@app.route('/trend')
def pie():
pie_labels = labels
pie_values = values
return render_template('pie_chart.html', title='Most Actively Partcipating Hospitals', max=17000, set=zip(values, labels, colors))
@app.route('/faq')
def faq():
if not session.get('logged_in'):
return render_template('login.html')
return render_template('doctq.html')
@app.route('/findp')
def find_student():
if not session.get('logged_in'):
return render_template('login.html')
return render_template('find.html')
@app.route('/addrec',methods = ['POST', 'GET'])
def addrec():
if not session.get('logged_in'):
return render_template('login.html')
if request.method == 'POST':
try:
i = request.form['id']
p = request.form['psswd']
n = request.form['nme']
h = request.form['hlth']
today = date.today()
me = request.form['medicine']
v = request.form['val']
with sql.connect("patient.db") as con:
cur = con.cursor()
cur.execute("INSERT INTO patients (pid,password,pname,visit,health,medication,value) VALUES (?,?,?,?,?,?,?)",(i,p,n,today,h,me,v) )
con.commit()
msg = "Record successfully added"
except:
con.rollback()
msg = "error in insert operation"
finally:
return render_template("result.html",msg = msg)
con.close()
@app.route('/addque',methods = ['POST', 'GET'])
def addque():
if not session.get('logged_in'):
return render_template('login.html')
if request.method == 'POST':
try:
qu = request.form['ques']
an = request.form['ans']
tp = request.form['typ']
url= 'http://chahalacademyexpenditures.hostingerapp.com/addhealth.php?questions='+qu+'&answers='+an+'&category='+tp
print(url)
except:
print("Error")
finally:
return redirect(url, code=302)
@app.route('/find',methods = ['POST', 'GET'])
def find():
if not session.get('logged_in'):
return render_template('login.html')
nm = request.form['nm']
con = sql.connect("patient.db")
con.row_factory = sql.Row
cur = con.cursor()
cur.execute("select * from patients where pid=?",(nm,))
rows = cur.fetchall();
return render_template("list2.html",rows = rows)
@app.route('/list')
def list():
if not session.get('logged_in'):
return render_template('login.html')
con = sql.connect("patient.db")
con.row_factory = sql.Row
cur = con.cursor()
cur.execute("select * from patients ")
rows = cur.fetchall();
return render_template("list2.html",rows = rows)
@app.route('/plist')
def plist():
if not session.get('logged_in'):
return render_template('login.html')
m=session.get('logged_in')
con = sql.connect("patient.db")
con.row_factory = sql.Row
cur = con.cursor()
cur.execute("select * from patients where pid=?",(m,))
rows = cur.fetchall();
return render_template("list.html",rows = rows)
if __name__ == '__main__':
app.run(debug = True,host= '0.0.0.0')