-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
108 lines (75 loc) · 2.7 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# IMPORT DEPENDENCIES
import os
from os import environ
import pandas as pd
import numpy as np
import datetime as dt
import sqlalchemy
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine
from flask import Flask, jsonify, render_template
from flask_sqlalchemy import SQLAlchemy
import pprint
# CREATE A FLASK INSTANCE
app = Flask(__name__)
# SETUP FLASK SQLALCHEMY
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get('SQLALCHEMY_DATABASE_URI')
db = SQLAlchemy(app)
# Create engine
conn_str = "postgres://zjfbqfjaacmfzh:020bd1ef15a08b5254c2958de00d93361dd7fe2751a492f1fc51c26cad45acaa@ec2-54-235-192-146.compute-1.amazonaws.com:5432/d6njntop4ptmpl"
engine = create_engine(conn_str)
# Reflect the database
Base = automap_base()
# Reflect the tables
Base.prepare(engine, reflect=True)
#Save reference to the table
Listing_detail_df_new = Base.classes.listing_detail_df_new
# Route to render index.html template using data
@app.route("/")
def index():
# Return template and data
return render_template("index.html")
@app.route("/growth_analysis_js")
def growthanalysisjsf():
# Create session
session = Session(engine)
# Query the table for columns of interest
hostsince = session.query(Listing_detail_df_new).all()
#Close the session
session.close()
# Create a list of dictionaries for each column
hosts_list = []
for Eachhost in hostsince:
hosts_dict = {}
hosts_dict["id"] = Eachhost.id
hosts_dict["host_since"] = Eachhost.host_since
hosts_list.append(hosts_dict)
# Return the json
return jsonify(hosts_list)
@app.route("/data_cleaning_ht")
def datacleaninghtf():
"""Return the Data Cleaning page of Airbnb html"""
return render_template("pg_data_cleaning.html")
@app.route("/growth_analysis_ht")
def growthanalysishtf():
"""Return the Growth analysis of Airbnb html"""
return render_template("pg_growth_analysis.html")
@app.route("/superhost_analysis_ht")
def superhostanalysishtf():
"""Return the super host analysis of Airbnb html"""
return render_template("pg_superhost_analysis.html")
@app.route("/price_analysis_ht")
def priceanalysishtf():
"""Return the price analysis of Airbnb html"""
return render_template("pg_price_analysis.html")
@app.route("/airbnb_locator_ht")
def airbnblocatorhtf():
"""Return the airbnb locator page"""
return render_template("airbnblocator.html")
@app.route("/review_analysis_ht")
def reviewanalysishtf():
"""Return the review analysis page"""
return render_template("reviewanalysis.html")
if __name__ == "__main__":
app.run(debug=True)