-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
90 lines (62 loc) · 1.97 KB
/
app.py
File metadata and controls
90 lines (62 loc) · 1.97 KB
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
#import dependencies
import os
#flask dependencies
from flask import Flask, render_template, jsonify
#sqlalchemy orm
from flask_sqlalchemy import SQLAlchemy
import sqlalchemy
from sqlalchemy.ext.automap import automap_base
from sqlalchemy import create_engine, MetaData
from sqlalchemy.orm import Session
#mysql dependencies
import pymysql
pymysql.install_as_MySQLdb()
import pandas as pd
is_prod = os.environ.get('IS_HEROKU', None)
if is_prod:
endpoint = os.environ.get('endpoint')
instance = os.environ.get('instance')
password = os.environ.get('password')
port = os.environ.get('port')
username = os.environ.get('username')
else:
from config import endpoint, username, password, instance, port
dburl= f"mysql://{username}:{password}@{endpoint}:{port}/{instance}"
app = Flask(__name__)
SQLALCHEMY_TRACK_MODIFICATIONS = False
app.config["SQLALCHEMY_DATABASE_URI"] = dburl
app.config['JSON_SORT_KEYS'] = False
db = SQLAlchemy(app)
engine = create_engine(f"mysql://{username}:{password}@{endpoint}:{port}/{instance}")
conn = engine.connect()
Base = automap_base()
Base.prepare(engine, reflect=True)
#Save reference to tables in the db
#Stocks_table = Base.classes.trending_stocks
@app.route("/")
def index():
return render_template('index.html')
@app.route("/visualizations")
def visuals():
return render_template('stocks.html')
@app.route("/scatter")
def scatter():
return render_template('d3.html')
@app.route("/skills")
def techincal_skills():
return render_template('skills.html')
@app.route("/mapping")
def maps():
return render_template('map.html')
@app.route("/ML")
def machine_learning():
return render_template('ML.html')
@app.route("/census_data")
def censusData():
conn = engine.connect()
#create list of column names
census_df = pd.read_sql("SELECT * FROM census_data", conn)
census_json = census_df.to_dict(orient="records")
return jsonify(census_json)
if __name__ == "__main__":
app.run(debug=True)