OpenWeatherLite
Inspired by a raspberry pi project from one that was collecting dust. Goal of the project was to create a simple circuit that would light up the appropriate led based on the current weather conditions. In my search to find a good, preferably free, api provider for weather I stumbled upon openweathermap.
After registering for a free api key, I wrote this ruby class to interface between my raspberry pi and the weather api. I had it ping every 30 seconds to get the latest weather and turn on an led or begin pulsating the led based on temperate and weather conditions.
Here are the details below.
Installation
Add this line to your application’s Gemfile:
And then execute:
$ bundle
Or install it yourself as:
$ gem install openweatherlite
Example
Usage
OpenWeatherLite::Weather
This class is the api class for openweather
attributes
api_key
units
(metric, imperial)
initialize
Provide an optional api_key
by_zip_code
Provide zip_code
and optionally country
. country
defaults to us
. Returns OpenWeatherLite::WeatherResponse
by_city_id
Provide a city_id
according to openweathermap and returns OpenWeatherLite::WeatherResponse
by_coords
Provide latitude
and longitude
and returns OpenWeatherLite::WeatherResponse
OpenWeatherLite::WeatherResponse
coords
Returns a hash of the coordinates
temperature
Returns the temperature value from the reponse. Unit is in units provided by to OpenWeatherLite::Weather
pressure
Returns the pressure value from the response
humidity
Returns the humidity value from the response
temperature_range
Returns an array
with the [min, max]
values from the response
wind
Returns the wind details hash
with speed
and deg
from the response
cloudy?
Returns true
or false
if there are any clouds
clouds
Returns the percentage of clouds in a hash
rainy?
Returns true
or false
depending on whether it is, or has rained in the past 3 hours
rain
Returns the amount that it has rained in the last 3 hours in a hash
snow?
Returns true
or false
depending on whether it is, or has rained in the past 3 hours
snow
Returns the amount that it has snowed in the last 3 hours in a hash
sunrise
Returns the time for sunrise today
sunset
Returns the time for sunset today
Source
Github source code: OpenWeatherLite