Optimizing API Requests Example


    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

    # Make the API request and get a list of ObservationResponse objects from the response 

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

    # (Note: we don't need a RequestLocation object, since we're using Closest with the "p" parameter.)
    obs_list = aeris.observations(action=RequestAction.OBSERVATIONS.CLOSEST,
                                  params={ParameterType.OBSERVATIONS.P: "minneapolis,mn",
                                          ParameterType.OBSERVATIONS.FIELDS: "place, ob.tempF,ob.weather"})

    for obs in obs_list:
        place = obs.place
        ob = obs.ob
        tempF = ob.tempF
        weather = ob.weather

        print("Optimizing API Requests Example:")
        print("The current weather for " + place.name + ", " + place.state + ":")
        print("Conditions are currently " + weather + " with a temp of " + str(tempF) + "°F")

Expected output:

Optimizing API Requests Example:
The current weather for saint louis park, mn:
Conditions are currently Mostly Cloudy with a temp of 65°F


*The actual values may vary