summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/Monitors
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2026-11-08 23:50:59 +0000
committerjao <jao@gnu.org>2026-11-08 23:50:59 +0000
commitdb39ee1c0ae7f7cd07db0c49d24471f1e7847168 (patch)
tree60c74747d17f98fe234ddb6842c59ec9d2e52ed8 /src/Xmobar/Plugins/Monitors
parent8b1ea0506277db1fbdf305e2b9a8edf4b4344802 (diff)
downloadxmobar-master.tar.gz
xmobar-master.tar.bz2
weather monitor: lintingHEADmaster
Diffstat (limited to 'src/Xmobar/Plugins/Monitors')
-rw-r--r--src/Xmobar/Plugins/Monitors/Weather.hs23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Weather.hs b/src/Xmobar/Plugins/Monitors/Weather.hs
index 6b5c353..7d31606 100644
--- a/src/Xmobar/Plugins/Monitors/Weather.hs
+++ b/src/Xmobar/Plugins/Monitors/Weather.hs
@@ -21,6 +21,7 @@ import qualified Control.Exception as CE
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Char (toLower)
+import Data.List (isPrefixOf)
import Network.HTTP.Conduit
import Network.HTTP.Types.Status
import Network.HTTP.Types.Method
@@ -232,13 +233,17 @@ formatWeather opts sks [WI st ss y m d h wind v sk we tC tF dC dF r p] =
cel <- showWithColors show tC
far <- showWithColors show tF
let we' = showWeather (weatherString opts) we
- sk' = findSk sks (map toLower sk) we'
- we'' = findSk sks (map toLower we') sk'
+ sk' = find sks (map toLower sk) we'
+ we'' = find sks (map toLower we') sk'
parseTemplate [st, ss, y, m, d, h, wc, wa, wm, wk, wkh
, wms, v, sk, sk', we', we'', cel, far
, show dC, show dF, show r , show p ]
- where findSk ((a,b):xs) x df = if a == x then b else findSk xs x df
- findSk [] _ df = df
+ where find _ "" o = o
+ find ((a,b):ab) k o = if a == k then b else find ab k o
+ find [] k o = find' sks k o
+ find' ((a,b):ab) k o = if a `isPrefixOf` k then b else find' ab k o
+ find' [] _ o = o
+
formatWeather _ _ _ = getConfigValue naString
-- | Show the 'weather' field with a default string in case it was empty.
@@ -276,14 +281,16 @@ runWeather
-> WeatherOpts -- ^ Weather specific options
-> [String] -- ^ User supplied arguments
-> Monitor String
-runWeather sks opts args = do
- d <- io $ getData (head args)
+runWeather sks opts (station:_) = do
+ d <- io $ getData station
i <- io $ runP parseData d
formatWeather opts sks i
+runWeather _ _ [] = return "<Missing weather station>"
weatherReady :: [String] -> Monitor Bool
-weatherReady str = io $ do
- initRequest <- parseUrlThrow $ stationUrl $ head str
+weatherReady [] = return False
+weatherReady (station:_) = io $ do
+ initRequest <- parseUrlThrow $ stationUrl station
let request = initRequest { method = methodHead }
CE.catch