-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
90 lines (73 loc) · 2.51 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
from flask import Flask, render_template, request,Response, flash
from client import Client
from CNS import Answer,Message
import pandas as pd
import toml
conf = toml.load("setup.toml")
server_config = conf.get("database")
records = server_config.get("records")
# ---------------------------------------------
Dict_record = {"phone_number":records[0],
"email_institute":records[1],
"email_personal":records[2],
"section":records[3]}
# ------------------------------------------------
c = Client("setup.toml")
app = Flask(__name__)
app.config['SECRET_KEY'] = '21a00ee024ebe902cf1848208f5c1a29'
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 1
df=pd.DataFrame()
def Process_msg(msg: Message, required_fields):
arr = []
j=0
for answer in msg.answers:
if(answer.status_code == 0):
arr.append({"No records Found for this user":""})
else:
ret_records = answer.records
field_name = required_fields[j]
d1 = [[field_name[i],ret_records[i]] for i in range(len(ret_records))]
d = dict(d1)
arr.append(d)
j+=1
return arr
@app.route('/')
def student():
return render_template('lol.html')
@app.route('/result',methods = ['POST', 'GET'])
def result():
if request.method == 'POST':
result = request.form
number=int(result['number'])
names=[]
required_fields=[]
for i in range(1,number+1):
names.append(result['textbox'+str(i)])
required_fields.append(result.getlist('interest'+str(i)))
print(names,required_fields)
for required_field in required_fields:
if(len(required_field)==0):
flash('Please select atleast one field !!', 'danger')
return render_template("lol.html")
for i in range(len(required_fields)):
required_fields[i] = list(map(Dict_record.get,required_fields[i]))
qry_lst = [[names[i],required_fields[i]] for i in range(number)]
c.make_qrymsg(qry_lst,True)
c.send_qry()
d = c.rcv_msg()
d = Message.decode(d)
p_msg = Process_msg(d, required_fields)
global df
df=pd.DataFrame(p_msg,index=names)
return render_template("result.html",output=dict(zip(names,p_msg)))
@app.route('/download')
def download():
global df
#print(df.index)
return Response(
df.to_csv(),
mimetype="text/csv",
headers={"Content-disposition":
"attachment; filename=filename.csv"})
if __name__ == '__main__':
app.run(debug = True)