List all the available routes. 2) /api/v1.0/precipitation Convert the query results from your precipitation analysis (i.e. retrieve
Question:
List all the available routes.
2) /api/v1.0/precipitation
Convert the query results from your precipitation analysis (i.e. retrieve only the last 12 months of data) to a dictionary using date as the key and prcp as the value.
Return the JSON representation of your dictionary.
3) /api/v1.0/stations
- Return a JSON list of stations from the dataset.
4) /api/v1.0/tobs
Query the dates and temperature observations of the most-active station for the previous year of data.
Return a JSON list of temperature observations for the previous year.
5) /api/v1.0/ and /api/v1.0//
Return a JSON list of the minimum temperature, the average temperature, and the maximum temperature for a specified start or start-end range.
For a specified start, calculate TMIN, TAVG, and TMAX for all the dates greater than or equal to the start date.
For a specified start date and end date, calculate TMIN, TAVG, and TMAX for the dates from the start date to the end date, inclusive.
# Import the dependencies.from flask import Flask, jsonifyfrom sqlalchemy import create_engine, funcfrom sqlalchemy.orm import Sessionfrom sqlalchemy.ext.automap import automap_baseimport datetime as dt#database setupengine = create_engine("sqlite:///Resources/hawaii.sqlite")Base = automap_base()Base.prepare(engine, reflect=True)Measurement = Base.classes.measurementStation = Base.classes.stationsession = Session(engine)#instance of the Flask classapp = Flask(__name__)@app.route("/")def home(): """List all available api routes.""" return ( f"Available Routes: " f"/api/v1.0/precipitation " f"/api/v1.0/stations " f"/api/v1.0/tobs " f"/api/v1.0/ " f"/api/v1.0//" )@app.route("/api/v1.0/precipitation")def precipitation(): """Return a list of precipitation data""" # Query all precipitation data results = session.query(Measurement.date, Measurement.prcp).all() # Convert list of tuples into normal list precipitation_data = dict(results) return jsonify(precipitation_data)@app.route("/api/v1.0/stations")def stations(): """Return a list of all station names""" # Query all stations results = session.query(Station.station).all() # Convert list of tuples into normal list stations = list(np.ravel(results)) return jsonify(stations)@app.route("/api/v1.0/tobs")def tobs(): """Return a list of temperature observations for the previous year""" # Query all tobs results = session.query(Measurement.date, Measurement.tobs).filter(Measurement.date >= '2016-08-23').all() # Convert list of tuples into normal list tobs_data = list(np.ravel(results)) return jsonify(tobs_data)#define main behavior