System.Taffybar.Weather
Contents
Description
This module defines a simple textual weather widget that polls NOAA for weather data. To find your weather station, you can use
http://lwf.ncdc.noaa.gov/oa/climate/stationlocator.html
For example, Madison, WI is KMSN.
NOAA provides several pieces of information in each request; you
can control which pieces end up in your weather widget by providing
a _template_ that is filled in with the current information. The
template is just a String with variables between dollar signs.
The variables will be substituted with real data by the widget.
Example:
let wcfg = (defaultWeatherConfig "KMSN") { weatherTemplate = "$tempC$ C @ $humidity$" }
weatherWidget = weatherNew wcfg 10
This example makes a new weather widget that checks the weather at KMSN (Madison, WI) every 10 minutes, and displays the results in Celcius.
Available variables:
stationPlace- The name of the weather station
stationState- The state that the weather station is in
year- The year the report was generated
month- The month the report was generated
day- The day the report was generated
hour- The hour the report was generated
wind- The direction and strength of the wind
visibility- Description of current visibility conditions
skyCondition- ?
tempC- The temperature in Celcius
tempF- The temperature in Farenheit
dewPoint- The current dew point
humidity- The current relative humidity
pressure- The current pressure
As an example, a template like
"$tempF$ F"
would yield a widget displaying the temperature in Farenheit with a small label after it.
Implementation Note: the weather data parsing code is taken from xmobar. This version of the code makes direct HTTP requests instead of invoking a separate cURL process.
- data WeatherConfig = WeatherConfig {}
- data WeatherInfo = WI {}
- data WeatherFormatter = WeatherFormatter (WeatherInfo -> String)
- weatherNew :: WeatherConfig -> Double -> IO Widget
- defaultWeatherConfig :: String -> WeatherConfig
Types
data WeatherConfig Source
The configuration for the weather widget. You can provide a custom
format string through weatherTemplate as described above, or you can
provide a custom function to turn a WeatherInfo into a String via the
weatherFormatter field.
Constructors
| WeatherConfig | |
Fields
| |
data WeatherFormatter Source
A wrapper to allow users to specify a custom weather formatter. The default interpolates variables into a string as described above. Custom formatters can do basically anything.
Constructors
| WeatherFormatter (WeatherInfo -> String) | Specify a custom formatter for |
Constructor
Arguments
| :: WeatherConfig | Configuration to render |
| -> Double | Polling period in _minutes_ |
| -> IO Widget |
Create a periodically-updating weather widget that polls NOAA.
defaultWeatherConfig :: String -> WeatherConfigSource
A sensible default configuration for the weather widget that just renders the temperature.