summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/Monitors/Weather.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2019-06-29 23:16:49 +0100
committerjao <jao@gnu.org>2019-06-29 23:16:49 +0100
commita160cc25ba27b17e798f9d0eadd2c9576473ae9a (patch)
tree3ff90d9fea66ce3ec32d86495b40eaa1e0894141 /src/Xmobar/Plugins/Monitors/Weather.hs
parent7aeb01c7dc010bd621d22bf342c599b4df9a1392 (diff)
downloadxmobar-a160cc25ba27b17e798f9d0eadd2c9576473ae9a.tar.gz
xmobar-a160cc25ba27b17e798f9d0eadd2c9576473ae9a.tar.bz2
New WeatherX variant with sky conditions translations
Diffstat (limited to 'src/Xmobar/Plugins/Monitors/Weather.hs')
-rw-r--r--src/Xmobar/Plugins/Monitors/Weather.hs26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Weather.hs b/src/Xmobar/Plugins/Monitors/Weather.hs
index 30439f5..fb5732b 100644
--- a/src/Xmobar/Plugins/Monitors/Weather.hs
+++ b/src/Xmobar/Plugins/Monitors/Weather.hs
@@ -23,6 +23,7 @@ import Network.HTTP.Conduit
import Network.HTTP.Types.Status
import Network.HTTP.Types.Method
import qualified Data.ByteString.Lazy.Char8 as B
+import Data.Char (toLower)
import Text.ParserCombinators.Parsec
@@ -43,6 +44,7 @@ weatherConfig = mkMConfig
, "windMs"
, "visibility"
, "skyCondition"
+ , "skyConditionS"
, "tempC"
, "tempF"
, "dewPointC"
@@ -194,18 +196,28 @@ getData station = CE.catch (do
where errHandler :: CE.SomeException -> IO String
errHandler _ = return "<Could not retrieve data>"
-formatWeather :: [WeatherInfo] -> Monitor String
-formatWeather [WI st ss y m d h (WindInfo wc wa wm wk wkh wms) v sk tC tF dC dF r p] =
+formatSk :: Eq p => [(p, p)] -> p -> p
+formatSk ((a,b):sks) sk = if a == sk then b else formatSk sks sk
+formatSk [] sk = sk
+
+formatWeather :: [(String,String)] -> [WeatherInfo] -> Monitor String
+formatWeather sks [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, wkh, wms, v, sk, cel, far, show dC, show dF, show r , show p ]
-formatWeather _ = getConfigValue naString
+ let sk' = formatSk sks (map toLower sk)
+ parseTemplate [st, ss, y, m, d, h, wc, wa, wm, wk, wkh
+ , wms, v, sk, sk', cel, far
+ , show dC, show dF, show r , show p ]
+formatWeather _ _ = getConfigValue naString
runWeather :: [String] -> Monitor String
-runWeather str =
- do d <- io $ getData $ head str
+runWeather = runWeather' []
+
+runWeather' :: [(String, String)] -> [String] -> Monitor String
+runWeather' sks args =
+ do d <- io $ getData $ head args
i <- io $ runP parseData d
- formatWeather i
+ formatWeather sks i
weatherReady :: [String] -> Monitor Bool
weatherReady str = do