-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
94 lines (79 loc) · 2.44 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
import pandas as pd
import numpy as np
from sqlalchemy import create_engine, inspect
import sqlalchemy as db
# Import Dependencies
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import func
from flask import Flask, jsonify, render_template
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
launch_data_df = pd.read_csv('Global Space Launches -separate columns final2.csv',encoding="ISO-8859-1")
launch_data_df.head()
url = 'postgresql://postgres:postgres@localhost:5432/gt_project2'
engine = db.create_engine(url)
launch_data_df.to_sql(name='launch_data', con=engine, if_exists='replace', index=False)
connection = engine.connect()
metadata = db.MetaData()
launch_data = db.Table('launch_data', metadata, autoload=True, autoload_with=engine)
session = Session(bind = engine)
results = session.query(launch_data).all()
# Create a dictionary entry for each row of data information
inspector = inspect(engine)
columns = inspector.get_columns('launch_data')
column_names = [column['name'] for column in columns]
final_results = []
for result in results:
my_dict = {}
for index, value in enumerate(result):
my_dict[column_names[index]] = value
final_results.append(my_dict)
session.close()
##########
# HOME PAGE
##########
@app.route("/")
def index():
"""Return the homepage."""
return render_template("index.html")
@app.route("/index.html")
def home():
"""Return the homepage."""
return render_template("index.html")
##########
# API DATA
##########
# launch Data
@app.route("/api/launch_data")
def launchdata():
return jsonify(final_results)
##########
# VISUALIZATIONS
##########
@app.route("/graphs.html")
def graphs():
"""Return the graphs page."""
return render_template("graphs.html")
@app.route("/graphsKelly.html")
def graphs_kelly():
"""Return the graphs page."""
return render_template("graphs-Kelly.html")
@app.route("/maps.html")
def build_maps():
"""Return the US_OP page."""
return render_template("maps.html")
@app.route("/aboutus.html")
def aboutus():
"""Return the states_map page."""
return render_template("aboutUs.html")
@app.route("/rawdata.html")
def rawData():
"""Return the states_map page."""
return render_template("data.html")
@app.route("/csvdata.html")
def csvdata():
"""Return the states_map page."""
return render_template("data.html")
if __name__ == "__main__":
app.run(debug=True)