forked from john-guerra/flask_d3_example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw209.py
23 lines (17 loc) · 729 Bytes
/
w209.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from flask import Flask, render_template
app = Flask(__name__)
import pandas as pd
import os
APP_FOLDER = os.path.dirname(os.path.realpath(__file__))
@app.route("/")
def hello():
return render_template("index.html")
@app.route("/getData/<int:year>")
def getData(year):
# Load the CSV file from the static folder, inside the current path
revenue = pd.read_csv(os.path.join(APP_FOLDER,"static/data/1_Revenues.csv"))
if year < 1942 or year > 2008:
return "Error in the year range"
filteredRevenue = revenue[revenue['Year4']==year][["Name","Year4", "Total Revenue","Population (000)"]]
# show the post with the given id, the id is an integer
return filteredRevenue.to_json(orient='records')