-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
64 lines (53 loc) · 1.48 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
from flask import Flask, render_template, url_for, request, json, session, redirect
app = Flask(__name__)
# posts = [
# {
# 'Crime': 'Alcohol',
# 'State': 'NC'
# },
# {
# 'Crime': 'Felony',
# 'State': 'CA'
# }
# ]
def compar(state, crime):
with open('combine.json', 'r') as f :
data = json.load(f)
lst = data["final"]
for each_state in lst:
if list(each_state.keys())[0] == state:
all_id = list(each_state.values())[0]
for eachid in all_id:
if eachid[0] == crime:
sp = eachid[1]
return sp
return "Not Found"
@app.route("/")
def index():
return render_template('index.html')
@app.route("/", methods=['POST', 'GET'])
def fetch():
result = []
crime = request.form['crime']
state = request.form['state']
print(state)
try:
state = list(state.split(', '))
except ValueError:
pass
# print(state)
for i in state:
print(i)
result.append(compar(i, crime))
print(result)
session['result'] = result
if result == []:
return "Not Found"
return redirect(url_for('output'))
@app.route("/ouput")
def output():
result = session.get('result', None)
return render_template('output.html', result=result)
if __name__ == '__main__':
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
app.run(debug=True)