summaryrefslogtreecommitdiffhomepage
path: root/src
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
parent7aeb01c7dc010bd621d22bf342c599b4df9a1392 (diff)
downloadxmobar-a160cc25ba27b17e798f9d0eadd2c9576473ae9a.tar.gz
xmobar-a160cc25ba27b17e798f9d0eadd2c9576473ae9a.tar.bz2
New WeatherX variant with sky conditions translations
Diffstat (limited to 'src')
-rw-r--r--src/Xmobar/Plugins/Monitors.hs6
-rw-r--r--src/Xmobar/Plugins/Monitors/Weather.hs26
2 files changed, 24 insertions, 8 deletions
diff --git a/src/Xmobar/Plugins/Monitors.hs b/src/Xmobar/Plugins/Monitors.hs
index 3e7584f..8ce5300 100644
--- a/src/Xmobar/Plugins/Monitors.hs
+++ b/src/Xmobar/Plugins/Monitors.hs
@@ -3,7 +3,7 @@
-----------------------------------------------------------------------------
-- |
-- Module : Xmobar.Plugins.Monitors
--- Copyright : (c) 2010, 2011, 2012, 2013, 2017, 2018 Jose Antonio Ortega Ruiz
+-- Copyright : (c) 2010, 2011, 2012, 2013, 2017, 2018, 2019 Jose Antonio Ortega Ruiz
-- (c) 2007-10 Andrea Rossato
-- License : BSD-style (see LICENSE)
--
@@ -78,6 +78,7 @@ data Monitors = Network Interface Args Rate
| CatInt Int FilePath Args Rate
#ifdef WEATHER
| Weather Station Args Rate
+ | WeatherX Station SkyConditions Args Rate
#endif
#ifdef UVMETER
| UVMeter Station Args Rate
@@ -103,6 +104,7 @@ type Args = [String]
type Program = String
type Alias = String
type Station = String
+type SkyConditions = [(String, String)]
type Zone = String
type ZoneNo = Int
type Interface = String
@@ -112,6 +114,7 @@ type DiskSpec = [(String, String)]
instance Exec Monitors where
#ifdef WEATHER
alias (Weather s _ _) = s
+ alias (WeatherX s _ _ _) = s
#endif
alias (Network i _ _) = i
alias (DynNetwork _ _) = "dynnetwork"
@@ -159,6 +162,7 @@ instance Exec Monitors where
start (TopMem a r) = runM a topMemConfig runTopMem r
#ifdef WEATHER
start (Weather s a r) = runMD (a ++ [s]) weatherConfig runWeather r weatherReady
+ start (WeatherX s c a r) = runMD (a ++ [s]) weatherConfig (runWeather' c) r weatherReady
#endif
start (Thermal z a r) = runM (a ++ [z]) thermalConfig runThermal r
start (ThermalZone z a r) =
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