-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
62 lines (49 loc) · 1.65 KB
/
api.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
from flask import Flask, request, render_template,jsonify,send_from_directory,safe_join
import csv
import json
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/map')
def map_view():
return render_template('MapView.html')
@app.route('/chart')
def chart_view():
return render_template('ChartView.html')
@app.route('/table')
def table_view():
return render_template('TableView.html')
@app.route('/data/<path:filename>')
def custom_static(filename):
return send_from_directory('data', filename, as_attachment=False)
@app.route('/query', methods=['GET','POST'])
def query_selected_post():
reqFilter = request.args.get('requestType')
reqVal = request.args.get('requestValue')
csv_file = csv.reader(open('data/mass_shootings.csv', "r"), delimiter=",")
jsonData = {}
counter = 0
for row in csv_file:
#if current rows 2nd value is equal to input, print that row
if reqVal == 'ALL':
jsonData[counter] = row
counter +=1
if reqVal == row[18] and reqFilter == 'raceSelect':
jsonData[counter] = row
counter +=1
if reqVal == row[11] and reqFilter == 'ageSelect':
jsonData[counter] = row
counter +=1
return jsonify(result=jsonData)
@app.route('/queryall', methods=['GET','POST'])
def query_all_post():
csv_file = csv.reader(open('data/mass_shootings.csv', "r"), delimiter=",")
jsonData = {}
counter = 0
for row in csv_file:
jsonData[counter] = row
counter +=1
return jsonify(result=jsonData)
if __name__ == '__main__':
app.run(debug=True)