Weather Library

These functions provide access to get current weather and forecasts by longitude/latitude coordinates.

If you have your own OpenWeatherMap account, you can use the OpenWeatherMap Library instead and it will use 1 Workflow Credit instead of 100.

 

Import

To use this library and its functions, you must use the import line at the beginning of your Base Python code.

import Weather

 

Get weather

Weather.get_weather_by_coordinates(lat, lon)

Get current weather for provided coordinates.

Credit cost: 100

Parameters

    • latdouble latitude
    • londouble longitude

Return Value

dict containing weather information

Example

    • Sample Code:
      • import Weather
        import json
        lat = 37.426048 lon = -121.975243 data = Weather.get_weather_by_coordinates(lat, lon) log(json.dumps(data))
    •  Return Value:
      • {
           "main":{
              "temp":292.6,
              "pressure":1010,
              "temp_max":297.15,
              "temp_min":286.48,
              "humidity":41
           },
           "clouds":{
              "all":5
           },
           "sys":{
              "country":"US",
              "sunrise":1473169384,
              "type":1,
              "message":0.0037,
              "sunset":1473215296,
              "id":480
           },
           "dt":1473130255,
           "coord":{
              "lon":-121.98,
              "lat":37.43
           },
           "weather":[
              {
                 "icon":"50n",
                 "description":"mist",
                 "main":"Mist",
                 "id":701
              }
           ],
           "name":"Alviso",
           "cod":200,
           "id":5323631,
           "base":"cmc stations",
           "wind":{
              "deg":310,
              "speed":4.1
           }
        }

Exceptions

  • Exception
    • Any error communicating with weather service
    • Specified wrong city name, ZIP-code or city ID (OpenWeatherMap FAQ)

Get 5 day forecast

Weather.get_5_day_forecast_by_coordinates(lat, lon)

Get 5 day forecast for provided coordinates.

Credit cost: 100

Parameters

    • latdouble latitude
    • londouble longitude

Return Value

dict containing weather information, in 3-hour time buckets

Example

    • Sample Code:
      • import Weather
        import json
        lat = 37.426048 lon = -121.975243 data = Weather.get_5_day_forecast_by_coordinates(lat, lon) log(json.dumps(data))
    •  Return Value:
      • {"cod":"200","message":0.0082,"cnt":40,"list":[{"dt":1485799200,"main":{"temp":283.76,"temp_min":283.76,"temp_max":283.761,"pressure":1017.24,"sea_level":1026.83,"grnd_level":1017.24,"humidity":100,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":7.27,"deg":15.0048},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-01-30 18:00:00"},...],"city":{"id":1907296,"name":"Tawarano","coord":{"lat":35.0164,"lon":139.0077},"country":"none"}}

Exceptions

  • Exception
    • Any error communicating with weather service
    • Specified wrong city name, ZIP-code or city ID (OpenWeatherMap FAQ)

Get 16 day forecast

Weather.get_16_day_forecast_by_coordinates(lat, lon)

Get 16 day forecast for provided coordinates.

Credit cost: 100

Parameters

    • latdouble latitude
    • londouble longitude

Return Value

dict containing weather information, in 1-day time buckets

Example

    • Sample Code:
      • import Weather
        import json
        lat = 37.426048 lon = -121.975243 data = Weather.get_16_day_forecast_by_coordinates(lat, lon) log(json.dumps(data))
    •  Return Value:
      • {"cod":"200","message":0.0082,"cnt":40,"list":[{"dt":1485799200,"main":{"temp":283.76,"temp_min":283.76,"temp_max":283.761,"pressure":1017.24,"sea_level":1026.83,"grnd_level":1017.24,"humidity":100,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":7.27,"deg":15.0048},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-01-30 18:00:00"},...],"city":{"id":1907296,"name":"Tawarano","coord":{"lat":35.0164,"lon":139.0077},"country":"none"}}

Exceptions

  • Exception
    • Any error communicating with weather service
    • Specified wrong city name, ZIP-code or city ID (OpenWeatherMap FAQ)