Forecasts Example with Fields

Code:


    from aerisweather.aerisweather import AerisWeather
    from aerisweather.requests.ParameterType import ParameterType
    from aerisweather.requests.RequestLocation import RequestLocation
    from aerisweather.requests.RequestAction import RequestAction
    from aerisweather.requests.RequestFilter import RequestFilter
    from keys import client_id, client_secret, app_id


    # instantiate our aerisweather object
    aeris = AerisWeather(client_id=client_id, client_secret=client_secret, app_id=app_id)

    # Let's create a new RequestLocation, this time using a postal code
    loc = RequestLocation(postal_code="55124")

    # we'll limit the fields returned by the API too, to just the ones we need for our example
    forecast_list = aeris.forecasts(location=loc,
                                    params={ParameterType.FORECASTS.FIELDS: "periods.isDay, periods.maxTempF, periods.minTempF, periods.weather"})

    for forecast in forecast_list:
        # check to see if this is a day or night forecast
        if forecast.periods[0].isDay:
            day = forecast.periods[0]
            night = forecast.periods[1]
        else:
            day = forecast.periods[1]
            night = forecast.periods[0]
        
        print("Forecast Example:")
        print("Today expect " + day.weather + " with a high temp of " + str(day.maxTempF) + "°")
        print("Tonight will be " + night.weather + " with a low temp of " + str(night.minTempF) + "°")

Expected output:

Forecast Example:
Today expect Partly Cloudy with a high temp of 66°
Tonight will be Partly Cloudy with Light Showers Likely with a low temp of 48°

 

*The actual values may vary

Last modified: May 17, 2018