taffybar-0.4.5: A desktop bar similar to xmobar, but with more GUI

Safe Haskell | None
Language | Haskell2010

System.Taffybar.Weather

Contents

- Types
- Constructor

Description

This module defines a simple textual weather widget that polls NOAA for weather data. To find your weather station, you can use

http://www.nws.noaa.gov/tg/siteloc.php

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.

Synopsis

- data WeatherConfig = WeatherConfig {
  - weatherStation :: String
  - weatherTemplate :: String
  - weatherFormatter :: WeatherFormatter
  }
- data WeatherInfo = WI {
  - stationPlace :: String
  - stationState :: String
  - year :: String
  - month :: String
  - day :: String
  - hour :: String
  - wind :: String
  - visibility :: String
  - skyCondition :: String
  - tempC :: Int
  - tempF :: Int
  - dewPoint :: String
  - humidity :: Int
  - pressure :: Int
  }
- data WeatherFormatter = WeatherFormatter (WeatherInfo -> String)
- weatherNew :: WeatherConfig -> Double -> IO Widget
- weatherCustomNew :: IO (Either String WeatherInfo) -> String -> WeatherFormatter -> 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

weatherStation :: String

  The weather station to poll. No default

weatherTemplate :: String

  Template string, as described above. Default: $tempF$ °F

weatherFormatter :: WeatherFormatter

  Default: substitute in all interpolated variables (above)

data WeatherInfo Source

Constructors

WI |

Fields

stationPlace :: String
stationState :: String
year :: String
month :: String
day :: String
hour :: String
wind :: String
visibility :: String
skyCondition :: String
tempC :: Int
tempF :: Int
dewPoint :: String
humidity :: Int
pressure :: Int

Instances

Show WeatherInfo Source |

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 `WeatherInfo`

# Constructor

weatherNew Source

Arguments

:: WeatherConfig | Configuration to render
-> Double | Polling period in _minutes_
-> IO Widget |

Create a periodically-updating weather widget that polls NOAA.

weatherCustomNew Source

Arguments

:: IO (Either String WeatherInfo) | Weather querying action
-> String | Weather template
-> WeatherFormatter | Weather formatter
-> Double | Polling period in _minutes_
-> IO Widget |

Create a periodically-updating weather widget using custom weather getter

defaultWeatherConfig :: String -> WeatherConfig Source

A sensible default configuration for the weather widget that just renders the temperature.