forked from gitter-badger/Dismantled-Cataclysm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
204 lines (152 loc) · 5.7 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
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
from flask import Flask, render_template, request, url_for, flash, redirect
from werkzeug.utils import secure_filename
import json
import os
from sampleSpacy import spacy_data
app = Flask(__name__)
def get_data():
data_vic = {}
with open ("data/victim.json","r") as r:
data_vic = json.load(r)
#print(data_vic)
vic_ids = data_vic.keys()
data_array_vic = []
for keys in vic_ids:
data_vic[keys]["id"] = keys
data_array_vic.append(data_vic[keys])
data_vol = {}
with open ("data/volunteer.json","r") as read_f:
data_vol = json.load(read_f)
vol_ids = data_vol.keys()
data_array_vol = []
for keys in vol_ids:
data_vol[keys]["id"] = keys
data_array_vol.append(data_vol[keys])
return data_array_vol, data_array_vic
@app.route('/', methods=['GET'])
@app.route('/home', methods=['GET'])
def home():
data_array_vol, data_array_vic = get_data()
#print(len(data_array_vic))
return render_template("home.html", data_array_vic = data_array_vic, data_array_vol = data_array_vol)
@app.route('/homeassign', methods = ['POST'])
def homeassign():
data_array_vol, data_array_vic = get_data()
vic_id_being_assigned = ""
vol_code = ""
for i in data_array_vic:
try:
vol_code = request.form[i["id"]]
vic_id_being_assigned = i["id"]
except:
continue
break
# print(vic_id_being_assigned)
# print("esdgsd")
# print(vol_code)
if vol_code != "" :
for i in data_array_vol:
if i["id"] == vol_code:
i["alloted"].append(vic_id_being_assigned)
new_vol = {}
with open ("data/volunteer.json","r") as read_f:
new_vol = json.load( read_f)
new_vol[i["id"]]["alloted"] = i["alloted"]
with open ("data/volunteer.json","w") as wri:
json.dump(new_vol,wri)
#vic_id_being_assigned = i["id"]
new_vic = {}
with open ("data/victim.json","r") as read_f:
new_vic = json.load( read_f)
new_vic[vic_id_being_assigned]["status"] = "Assigned to " + str(vol_code)
new_vic[vic_id_being_assigned]["alloted_to"] = vol_code
with open ("data/victim.json","w") as wri:
json.dump(new_vic,wri)
data_array_vol, data_array_vic = get_data()
return render_template("home.html", data_array_vic = data_array_vic, data_array_vol = data_array_vol)
@app.route('/homeSubmitVictim', methods = ['POST'])
def homeSubmitVictim():
new_data = request.form['victim_form']
#print("\n\n\nasfsdgds\n\n")
#print(new_data)
data_array_vol, data_array_vic = get_data()
i = len(data_array_vic) +1
name = []
activity =[]
donation =[]
add = []
number_of_people = []
name, activity, donation, add, number_of_people= spacy_data(new_data)
new_id = {}
new_id["vic" + str(i)] = {}
new_id["vic" + str(i)]["data"] = {}
count =0
if len(name) >0:
new_id["vic" + str(i)]["data"]["name"] = name
count+=1
if len(activity) >0:
new_id["vic" + str(i)]["data"]["ailment"] = activity
count+=1
if len(add) >0:
strr='.'
while strr in add:
add.remove(strr)
new_id["vic" + str(i)]["data"]["location"] = list(set(add))
count+=1
if len(number_of_people) >0:
count+=1
new_id["vic" + str(i)]["data"]["no of people"] = number_of_people
if count == 0 :
new_id["vic" + str(i)]["data"]["Undetected_text"] = new_data
new_id["vic" + str(i)]["status"] = "Unanswered"
new_id["vic" + str(i)]["alloted_to"] = "None"
data_vic = {}
with open ("data/victim.json","r") as read_f:
data_vic = json.load(read_f)
data_vic["vic" + str(i)] = new_id["vic" + str(i)]
with open("data/victim.json","w") as w:
json.dump(data_vic,w)
data_array_vol, data_array_vic = get_data()
return render_template("home.html", data_array_vic = data_array_vic, data_array_vol = data_array_vol)
@app.route('/homeSubmitVolunteer', methods = ['POST'])
def homeSubmitVolunteer():
new_data = request.form['volunteer_form']
data_array_vol, data_array_vic = get_data()
i = len(data_array_vol) + 1
name, activity, donation, add, number_people = spacy_data(new_data)
new_id = {}
new_id["vol" + str(i)] = {}
new_id["vol" + str(i)]["data"] = {}
count = 0
if len(name) >0:
count+=1
new_id["vol" + str(i)]["data"]["name"] = name
if len(donation) >0:
count +=1
new_id["vol" + str(i)]["data"]["donation"] = donation
if len(add) >0:
strr='.'
while strr in add:
add.remove(strr)
if len(add) >0:
new_id["vol" + str(i)]["data"]["location"] = list(set(add))
if len(number_people) >0:
count +=1
new_id["vol" + str(i)]["data"]["number of people"] = number_people
if count == 0 :
new_id["vol" + str(i)]["data"]["Undetected_text"] = new_data
new_id["vol" + str(i)]["alloted"] = []
new_id["vol" + str(i)]["alloted_to"] = "None"
data_vol = {}
with open ("data/volunteer.json","r") as read_f:
data_vol = json.load(read_f)
data_vol["vol" + str(i)] = new_id["vol" + str(i)]
with open("data/volunteer.json","w") as w:
json.dump(data_vol,w)
data_array_vol, data_array_vic = get_data()
return render_template("home.html", data_array_vic = data_array_vic, data_array_vol = data_array_vol)
@app.errorhandler(404)
def pageNotFound(e):
return ("Page Does Not Exist")
if __name__ == "__main__":
app.run(debug=True)