OpenWeatherMap Library

The following functions provide OpenWeatherMap weather capabilities to get current weather and 5 day forecasts by longitude/latitude coordinates. If you do not have a OpenWeatherMap account, you can use the Weather Library, however, that library will use 100 Workflow Credits instead of 1.

 

Import

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

import OpenWeatherMap

 

Get weather

OpenWeatherMap.get_weather_by_coordinates(lat, lon, apikey)

Get current weather for provided coordinates.

Credit cost: 1

Parameters

  • latdouble latitude
  • londouble longitude
  • apikeystring OpenWeatherMap API Key

Return Value

dict containing weather information

Example

  • Sample Code:
    • import OpenWeatherMap
      import json
      from my import keys
      apikey = keys.open_weather_map lat = 37.426048 lon = -121.975243 data = OpenWeatherMap.get_weather_by_coordinates(lat, lon, apikey) 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

OpenWeatherMap.get_5_day_forecast_by_coordinates(lat, lon, apikey)

Get 5 day forecast for provided coordinates.

Credit cost: 1

Parameters

  • latdouble latitude
  • londouble longitude
  • apikeystring OpenWeatherMap API Key

Return Value

dict containing weather information

Example

  • Sample Code:
    • import OpenWeatherMap
      import json
      from my import keys
      apikey = keys.open_weather_map lat = 37.426048 lon = -121.975243 data = OpenWeatherMap.get_5_day_forecast_by_coordinates(lat, lon, apikey) 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)