summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins
diff options
context:
space:
mode:
authorTony Morris <tmorris@tmorris.net>2014-09-01 10:54:06 +1000
committerjao <jao@gnu.org>2014-09-01 04:12:05 +0200
commitfa9d7f775769594f82bae2e2808cae9af5169472 (patch)
treea1539f0b0ee6b5940f400468794d63a0c63c67f2 /src/Plugins
parentd2e4eb58c83f09158076f3598a53ff3db8d480f8 (diff)
downloadxmobar-fa9d7f775769594f82bae2e2808cae9af5169472.tar.gz
xmobar-fa9d7f775769594f82bae2e2808cae9af5169472.tar.bz2
New wind report variables for Weather monitor
* Wind cardinal direction (`windCardinal`) * Wind azimuth direction (`windAzimuth`) * Wind speed (MPH) (`windMph`) * Wind speed (knots) (`windKnots`)
Diffstat (limited to 'src/Plugins')
-rw-r--r--src/Plugins/Monitors/Weather.hs42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/Plugins/Monitors/Weather.hs b/src/Plugins/Monitors/Weather.hs
index 93467ed..8119842 100644
--- a/src/Plugins/Monitors/Weather.hs
+++ b/src/Plugins/Monitors/Weather.hs
@@ -22,7 +22,6 @@ import Network.HTTP
import Text.ParserCombinators.Parsec
-
weatherConfig :: IO MConfig
weatherConfig = mkMConfig
"<station>: <tempC>C, rh <rh>% (<hour>)" -- template
@@ -32,7 +31,10 @@ weatherConfig = mkMConfig
, "month"
, "day"
, "hour"
- , "wind"
+ , "windCardinal"
+ , "windAzimuth"
+ , "windMph"
+ , "windKnots"
, "visibility"
, "skyCondition"
, "tempC"
@@ -50,7 +52,10 @@ data WeatherInfo =
, month :: String
, day :: String
, hour :: String
- , wind :: String
+ , windCardinal :: String
+ , windAzimuth :: String
+ , windMph :: String
+ , windKnots :: String
, visibility :: String
, skyCondition :: String
, tempC :: Int
@@ -70,7 +75,28 @@ pTime = do y <- getNumbersAsString
char ' '
(h:hh:mi:mimi) <- getNumbersAsString
char ' '
- return (y, m, d ,[h]++[hh]++":"++[mi]++mimi)
+ return (y, m, d ,h:hh:":"++mi:mimi)
+
+pWind ::
+ Parser (
+ String -- cardinal direction
+ , String -- azimuth direction
+ , String -- speed (MPH)
+ , String -- speed (knot)
+ )
+pWind =
+ let tospace = manyTill anyChar (char ' ')
+ wind = do manyTill skipRestOfLine (string "Wind: from the ")
+ cardinal <- tospace
+ char '('
+ azimuth <- tospace
+ string "degrees) at "
+ mph <- tospace
+ string "MPH ("
+ knot <- tospace
+ manyTill anyChar newline
+ return (cardinal, azimuth, mph, knot)
+ in try wind <|> return ("a", "b", "c", "d")
pTemp :: Parser (Int, Int)
pTemp = do let num = digit <|> char '-' <|> char '.'
@@ -114,7 +140,7 @@ parseData =
)
skipRestOfLine >> getAllBut "/"
(y,m,d,h) <- pTime
- w <- getAfterString "Wind: "
+ (wc, wa, wm, wk) <- pWind
v <- getAfterString "Visibility: "
sk <- getAfterString "Sky conditions: "
skipTillString "Temperature: "
@@ -126,7 +152,7 @@ parseData =
skipTillString "Pressure (altimeter): "
p <- pPressure
manyTill skipRestOfLine eof
- return [WI st ss y m d h w v sk tC tF dC dF rh p]
+ return [WI st ss y m d h wc wa wm wk v sk tC tF dC dF rh p]
defUrl :: String
defUrl = "http://weather.noaa.gov/pub/data/observations/metar/decoded/"
@@ -142,10 +168,10 @@ getData station = do
errHandler _ = return "<Could not retrieve data>"
formatWeather :: [WeatherInfo] -> Monitor String
-formatWeather [WI st ss y m d h w v sk tC tF dC dF r p] =
+formatWeather [WI st ss y m d h wc wa wm wk v sk tC tF dC dF r p] =
do cel <- showWithColors show tC
far <- showWithColors show tF
- parseTemplate [st, ss, y, m, d, h, w, v, sk, cel, far, show dC, show dF, show r , show p ]
+ parseTemplate [st, ss, y, m, d, h, wc, wa, wm, wk, v, sk, cel, far, show dC, show dF, show r , show p ]
formatWeather _ = getConfigValue naString
runWeather :: [String] -> Monitor String