-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.py
More file actions
249 lines (211 loc) · 5.52 KB
/
web.py
File metadata and controls
249 lines (211 loc) · 5.52 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
from flask import Flask
from flask import render_template, redirect, request, session
from twilio.rest import Client
import matplotlib.pyplot as plt
import matplotlib.animation as ani
import numpy as np
import pandas as pd
import tkinter
from operator import itemgetter
import csv
import smtplib
from email.mime.text import MIMEText
from prettytable import from_csv
# SocketServer.TCPServer.allow_reuse_address = True
# open file
def tkn():
root = tkinter.Tk()
with open("Warddetails.csv", newline = "") as file:
reader = csv.reader(file)
# r and c tell us where to grid the labels
r = 0
for col in reader:
c = 0
for row in col:
# i've added some styling
label = tkinter.Label(root, width = 20, height = 2, \
text = row, relief = tkinter.RIDGE)
label.grid(row = r, column = c)
c += 1
r += 1
root.mainloop()
app = Flask(__name__)
# data = [
# {'wardId' : '1', 'wardName' : 'Kormangala', 'com' : '25'},
# {'wardId' : '2', 'wardName' : 'Indiranagar', 'com' : '25'},
# {'wardId' : '3', 'wardName' : 'Whitefield', 'com' : '25'},
# {'wardId' : '4', 'wardName' : 'Brookefield', 'com' : '25'}
# ]
data =[]
df = pd.read_csv("Warddetails.csv")
containmentZone = []
for i in range(198):
a = {"wardNo": df["WardNo"][i],
"wardName": df["WardName"][i],
"com": df["Comorbidities"][i],
"red zone": df["ContainmentZone"][i],
"pos":df["ProbableCases"][i]}
data.append(a)
test = []
def func1(data):
temp = sorted(data, key=itemgetter('com'))
temp.reverse()
bus = []
rem = []
# flag = 0
van = 0
n = len(temp)
for i in range(3):
flag = 0
Bus = []
remTest = 100
for j in range(n):
if (temp[j]['red zone'] == 'Yes'):
continue
Busi = {}
if (remTest <= 0):
break
if (temp[j]['com'] == 0):
continue;
if (temp[j]['com'] >= 100):
temp[j]['com'] -= remTest
Busi['wardName'] = temp[j]['wardName']
Busi['com'] = remTest
remTest = 0
flag = 1
Bus.append(Busi);
break
else:
if (remTest >= temp[j]['com']):
Busi['wardName'] = temp[j]['wardName']
Busi['com'] = temp[j]['com']
remTest -= temp[j]['com']
temp[j]['com'] = 0
flag = 1
Bus.append(Busi)
else:
temp[j]['com'] -= remTest
Busi['wardName'] = temp[j]['wardName']
Busi['com'] = remTest
Bus.append(Busi)
flag = 1
remTest = 0;
break
if (flag == 1):
van += 1
bus.append(Bus)
if (van < 3):
while (van < 3):
flag = 0
Bus = []
remTest = 100
for j in range(n):
if (temp[j]['red zone'] == 'yes'):
continue
Busi = {}
if (remTest <= 0):
break
if (temp[j]['pos'] == 0):
continue;
if (temp[j]['pos'] >= 100):
temp[j]['pos'] -= remTest
Busi['ward name'] = temp[j]['ward name']
Busi['com'] = remTest
remTest = 0
flag = 1
Bus.append(Busi);
break
else:
if (remTest >= temp[j]['pos']):
Busi['wardName'] = temp[j]['wardName']
Busi['com'] = temp[j]['pos']
remTest -= temp[j]['pos']
temp[j]['pos'] = 0
flag = 1
Bus.append(Busi)
else:
temp[j]['pos'] -= remTest
Busi['wardName'] = temp[j]['wardName']
Busi['com'] = remTest
Bus.append(Busi)
flag = 1
remTest = 0;
break
van += 1;
bus.append(Bus)
if (van == 3):
for i in range(n):
remi = {}
remi['wardName'] = temp[i]['wardName']
remi['Total remaining Tests to be performed'] = temp[i]['com'] + temp[i]['pos']
rem.append(remi)
# OUTPUT
data = rem
test = bus
return test
def warddet():
columns = ['WardNo','WardName','ContainmentZone','Comorbidities','ProbableCases','CompletelyVerified']
df = pd.read_csv('Warddetails.csv', names=columns)
return df
def persondet():
columns = ['Member Id','Ward No','Ward Name','Age','Gender','Symptoms']
df = pd.read_csv('PersonData.csv', names=columns)
return df
def message(number):
account_sid = 'Account_ID'
auth_token = 'Auth_token'
client = Client(account_sid, auth_token)
message = client.messages.create(
from_='Number',
body ='Hi, Testing team will arrive in 1-2 working days',
to = number
)
print(message.sid)
def email(em):
fromx = 'Email_ID'
to = em
msg = MIMEText('HI! Your Appointment for Covid-19 Testing is Scheduled')
msg['Subject'] = 'Covid-19 Testing'
msg['From'] = fromx
msg['To'] = to
server = smtplib.SMTP('smtp.gmail.com:Number')
server.starttls()
server.ehlo()
server.login('Email_ID', 'Password')
server.sendmail(fromx, to, msg.as_string())
server.quit()
@app.route('/')
def index(test = test,rem = data):
test = func1(data)
print(test)
return render_template('index.html',test = test,rem = rem)
@app.route('/message')
def msg():
return render_template('message.html')
@app.route('/sendmessage',methods = ['GET','POST'])
def msg1():
if(request.method == 'POST'):
number = str(request.form['number'])
message(number)
return redirect('/')
@app.route('/sendemail', methods = ['GET', 'POST'])
def msg2():
if(request.method == 'POST'):
em = str(request.form['email'])
email(em)
return redirect('/')
@app.route('/display1')
def dis():
df = warddet()
df = df.to_html()
print(type(df))
return render_template('display.html',df = df)
@app.route('/display2')
def dis2():
df = persondet()
df = df.to_html()
print(type(df))
return render_template('display.html',df = df)
@app.route('/update')
def update():
return redirect('/')