-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
37 lines (29 loc) · 1.04 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
from flask import Flask, app, jsonify, render_template
import pandas as pd
app = Flask(__name__)
def read_csv_and_handle_errors(file_path):
try:
df = pd.read_csv(file_path)
data = df.to_dict(orient='records')
return data
except FileNotFoundError:
return {'error': 'File not found'}, 404
except Exception as e:
return {'error': str(e)}, 500
@app.route('/')
def home():
return render_template("index.html")
@app.route("/api/suicides_data")
def api_suicides_data():
return jsonify(read_csv_and_handle_errors('Resources/suicides_data.csv'))
@app.route("/api/province_data")
def api_province_data():
return jsonify(read_csv_and_handle_errors('Resources/province_data.csv'))
@app.route("/api/pie_chart")
def pie_chart():
return jsonify(read_csv_and_handle_errors('Resources/pie_chart.csv'))
@app.route("/api/chart3data")
def chart3data():
return jsonify(read_csv_and_handle_errors('Resources/chart3data.csv'))
if __name__ == '__main__':
app.run(host="localhost", port=5000, debug=True)