summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.woodpecker/build.yaml4
-rw-r--r--src/Xmobar/Plugins/Monitors/Weather.hs23
2 files changed, 16 insertions, 11 deletions
diff --git a/.woodpecker/build.yaml b/.woodpecker/build.yaml
index ef33379..29ef7b1 100644
--- a/.woodpecker/build.yaml
+++ b/.woodpecker/build.yaml
@@ -5,9 +5,7 @@ matrix:
GHC:
# - '9.14' currently broken due to: https://github.com/gtk2hs/gtk2hs/issues/348
# - '9.12' currently broken due to: https://github.com/gtk2hs/gtk2hs/issues/348
- - '9.10'
- - '9.8'
- - '9.6'
+ - '9.10-bookworm'
steps:
- name: hlint
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