diff options
author | Michael Knabe <github@mfkhh.de> | 2015-12-09 19:41:16 +0100 |
---|---|---|
committer | Michael Knabe <github@mfkhh.de> | 2015-12-09 19:41:16 +0100 |
commit | 23aa6876b069f05b7f2c4791bb4b344a3a7387b2 (patch) | |
tree | 0fbbbb3dfb541e71b5a9332de07ab4c52d1e80dd /src/Plugins/Monitors/Weather.hs | |
parent | c6071cc0da601851381a7fd2954923556dcbc802 (diff) | |
download | xmobar-23aa6876b069f05b7f2c4791bb4b344a3a7387b2.tar.gz xmobar-23aa6876b069f05b7f2c4791bb4b344a3a7387b2.tar.bz2 |
Add template variables for wind speed in m/s and km/h to weather plugin
Diffstat (limited to 'src/Plugins/Monitors/Weather.hs')
-rw-r--r-- | src/Plugins/Monitors/Weather.hs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/Plugins/Monitors/Weather.hs b/src/Plugins/Monitors/Weather.hs index d458279..b2520a9 100644 --- a/src/Plugins/Monitors/Weather.hs +++ b/src/Plugins/Monitors/Weather.hs @@ -43,6 +43,8 @@ weatherConfig = mkMConfig , "windAzimuth" , "windMph" , "windKnots" + , "windKmh" + , "windMs" , "visibility" , "skyCondition" , "tempC" @@ -59,6 +61,8 @@ data WindInfo = , windAzimuth :: String -- azimuth direction , windMph :: String -- speed (MPH) , windKnots :: String -- speed (knot) + , windKmh :: String -- speed (km/h) + , windMs :: String -- speed (m/s) } deriving (Show) data WeatherInfo = @@ -91,7 +95,7 @@ pTime = do y <- getNumbersAsString return (y, m, d ,h:hh:":"++mi:mimi) noWind :: WindInfo -noWind = WindInfo "μ" "μ" "0" "0" +noWind = WindInfo "μ" "μ" "0" "0" "0" "0" pWind :: Parser WindInfo pWind = @@ -105,7 +109,7 @@ pWind = string "MPH (" knot <- tospace manyTill anyChar newline - return $ WindInfo "μ" "μ" mph knot + return $ WindInfo "μ" "μ" mph knot (toKmh knot) (toMs knot) wind = do manyTill skipRestOfLine (string "Wind: from the ") cardinal <- tospace char '(' @@ -115,8 +119,13 @@ pWind = string "MPH (" knot <- tospace manyTill anyChar newline - return $ WindInfo cardinal azimuth mph knot + return $ WindInfo cardinal azimuth mph knot (toKmh knot) (toMs knot) in try wind0 <|> try windVar <|> try wind <|> return noWind + where + toKmh knots = knots $* 1.852 + toMs knots = knots $* 0.514 + ($*) :: String -> Double -> String + op1 $* op2 = show (round ((read op1::Double) * op2)::Integer) pTemp :: Parser (Int, Int) pTemp = do let num = digit <|> char '-' <|> char '.' @@ -199,10 +208,10 @@ getData station = do #endif formatWeather :: [WeatherInfo] -> Monitor String -formatWeather [WI st ss y m d h (WindInfo wc wa wm wk) v sk tC tF dC dF r p] = +formatWeather [WI st ss y m d h (WindInfo wc wa wm wk wkh wms) v sk tC tF dC dF r p] = do cel <- showWithColors show tC far <- showWithColors show tF - parseTemplate [st, ss, y, m, d, h, wc, wa, wm, wk, v, sk, cel, far, show dC, show dF, show r , show p ] + parseTemplate [st, ss, y, m, d, h, wc, wa, wm, wk, wkh, wms, v, sk, cel, far, show dC, show dF, show r , show p ] formatWeather _ = getConfigValue naString runWeather :: [String] -> Monitor String |