diff options
| author | jao <jao@gnu.org> | 2026-11-08 23:50:59 +0000 |
|---|---|---|
| committer | jao <jao@gnu.org> | 2026-11-08 23:50:59 +0000 |
| commit | db39ee1c0ae7f7cd07db0c49d24471f1e7847168 (patch) | |
| tree | 60c74747d17f98fe234ddb6842c59ec9d2e52ed8 | |
| parent | 8b1ea0506277db1fbdf305e2b9a8edf4b4344802 (diff) | |
| download | xmobar-db39ee1c0ae7f7cd07db0c49d24471f1e7847168.tar.gz xmobar-db39ee1c0ae7f7cd07db0c49d24471f1e7847168.tar.bz2 | |
| -rw-r--r-- | src/Xmobar/Plugins/Monitors/Weather.hs | 23 |
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 |
