diff options
| author | Josh Rahm <rahm@google.com> | 2023-02-03 11:05:39 -0700 |
|---|---|---|
| committer | Josh Rahm <rahm@google.com> | 2023-02-03 11:05:39 -0700 |
| commit | 0ddcc4362ccab3a443d244c6c8beb7a1eef4d9a4 (patch) | |
| tree | 15fd78fd694f154d594f522a615b85107a771708 /xmobar | |
| parent | 1a102c45a442490c1f1efdcf769b2ead579cfff6 (diff) | |
| download | rde-0ddcc4362ccab3a443d244c6c8beb7a1eef4d9a4.tar.gz rde-0ddcc4362ccab3a443d244c6c8beb7a1eef4d9a4.tar.bz2 rde-0ddcc4362ccab3a443d244c6c8beb7a1eef4d9a4.zip | |
Rename spotify-control to media-control.
This is part of a plan to decouple Spotify from RDE.
Diffstat (limited to 'xmobar')
| -rw-r--r-- | xmobar/extras/weather/src/Main.hs | 101 |
1 files changed, 53 insertions, 48 deletions
diff --git a/xmobar/extras/weather/src/Main.hs b/xmobar/extras/weather/src/Main.hs index aa5a408..ccabc21 100644 --- a/xmobar/extras/weather/src/Main.hs +++ b/xmobar/extras/weather/src/Main.hs @@ -11,6 +11,7 @@ import Data.Aeson import Data.Aeson.Types (Parser) import qualified Data.ByteString.Lazy.Char8 import qualified Data.Char +import Data.List (isInfixOf) import qualified Data.Map import Data.Maybe (fromMaybe) import qualified Data.Text @@ -22,21 +23,21 @@ import Text.Printf (printf) -- Date time that easily comparable. data SillyTime = SillyTime - { sillyTimeDate :: String, - sillyTimeAMPM :: String, - sillyTimeTime :: String + { sillyTimeDate :: !String, + sillyTimeAMPM :: !String, + sillyTimeTime :: !String } deriving (Ord, Eq, Show) data CurrentCondition = CurrentCondition - { feelsLikeF :: String, - cloudCover :: String, - humidity :: String, - tempF :: String, - weatherDesc :: String, - windspeedMiles :: String, - winddir :: String, - observationTime :: SillyTime + { feelsLikeF :: !String, + cloudCover :: !String, + humidity :: !String, + tempF :: !String, + weatherDesc :: !String, + windspeedMiles :: !String, + winddir :: !String, + observationTime :: !SillyTime } deriving (Generic, Show) @@ -46,15 +47,15 @@ newtype NearestArea = NearestArea deriving (Generic, Show) data Astronomy = Astronomy - { sunrise :: SillyTime, - sunset :: SillyTime + { sunrise :: !SillyTime, + sunset :: !SillyTime } deriving (Generic, Show) data Weather = Weather - { currentCondition :: CurrentCondition, - nearestArea :: NearestArea, - astronomy :: Astronomy + { currentCondition :: !CurrentCondition, + nearestArea :: !NearestArea, + astronomy :: !Astronomy } deriving (Generic, Show) @@ -118,39 +119,38 @@ instance FromJSON Weather where =<< getFirst (v .: "weather") ) -conditionsIconDay :: Data.Map.Map String String +conditionsIconDay :: [(String -> Bool, String)] conditionsIconDay = - Data.Map.fromList - [ ("overcast", fc "#808080" "\63070"), - ("fair", fc "a0a0a0" "š"), - ("clear", fc "#ddcf04" "\58125"), - ("sunny", fc "#ddcf04" "\58125"), - ("mostly clear", fc "#00a3c4" "\57894"), - ("mostly sunny", fc "#ddcf04" "\58124"), - ("partly sunny", fc "#ddcf04" "\58124"), - ("fair", fc "#a0a0a0" "\127761"), - ("cloudy", fc "#a0a0a0" "\64143"), - ("overcast", fc "#808080" "\63070"), - ("partly cloudy", fc "#a0a0a0" "\64148"), - ("mostly cloudy", fc "#808080" "\63070"), - ("considerable cloudiness", fc "#a0a0a0" "\64381") - ] - -conditionsIconNight :: Data.Map.Map String String + [ ((== "overcast"), fc "#808080" "\63070"), + ((== "fair"), fc "a0a0a0" "š"), + ((== "clear"), fc "#ddcf04" "\58125"), + ((== "sunny"), fc "#ddcf04" "\58125"), + ((== "mostly clear"), fc "#00a3c4" "\57894"), + ((== "mostly sunny"), fc "#ddcf04" "\58124"), + ((== "partly sunny"), fc "#ddcf04" "\58124"), + ((== "fair"), fc "#a0a0a0" "\127761"), + ((== "cloudy"), fc "#a0a0a0" "\64143"), + ((== "overcast"), fc "#808080" "\63070"), + ((== "partly cloudy"), fc "#a0a0a0" "\64148"), + ((== "mostly cloudy"), fc "#808080" "\63070"), + ((== "considerable cloudiness"), fc "#a0a0a0" "\64381"), + (("snow" `isInfixOf`), fc "#a0a0f0" "\58138") + ] + +conditionsIconNight :: [(String -> Bool, String)] conditionsIconNight = - Data.Map.fromList - [ ("clear", fc "#00a3c4" "\61830"), - ("sunny", fc "#00a3c4" "\61830"), - ("mostly clear", fc "#00a3c4" "\57894"), - ("mostly sunny", fc "#00a3c4" "\57894"), - ("partly sunny", fc "#00a3c4" "\57894"), - ("fair", fc "#808080" "\127761"), - ("cloudy", fc "#808080" "\64143"), - ("overcast", fc "#404040" "\63070"), - ("partly cloudy", fc "#a0a0a0" "\57894"), - ("mostly cloudy", fc "#808080" "\63070"), - ("considerable cloudiness", fc "#a0a0a0" "\64381") - ] + [ ((== "clear"), fc "#00a3c4" "\61830"), + ((== "sunny"), fc "#00a3c4" "\61830"), + ((== "mostly clear"), fc "#00a3c4" "\57894"), + ((== "mostly sunny"), fc "#00a3c4" "\57894"), + ((== "partly sunny"), fc "#00a3c4" "\57894"), + ((== "fair"), fc "#808080" "\127761"), + ((== "cloudy"), fc "#808080" "\64143"), + ((== "overcast"), fc "#404040" "\63070"), + ((== "partly cloudy"), fc "#a0a0a0" "\57894"), + ((== "mostly cloudy"), fc "#808080" "\63070"), + ((== "considerable cloudiness"), fc "#a0a0a0" "\64381") + ] handleWeather :: Weather -> String handleWeather w = execWriter $ do @@ -186,7 +186,7 @@ handleWeather w = execWriter $ do tell $ fn 5 $ fromMaybe "?" $ - Data.Map.lookup (map Data.Char.toLower $ weatherDesc (currentCondition w)) conditions + findMatch (map Data.Char.toLower $ weatherDesc (currentCondition w)) conditions tell " " tell $ lightGrey $ fn 3 $ printf "%s°F" (tempF $ currentCondition w) @@ -203,6 +203,11 @@ handleWeather w = execWriter $ do fc :: String -> String -> String fc = printf "<fc=%s>%s</fc>" +findMatch :: a -> [(a -> Bool, b)] -> Maybe b +findMatch a ((f, b) : fs) | f a = Just b +findMatch a (_ : fs) = findMatch a fs +findMatch _ [] = Nothing + main :: IO () main = do (code, resp) <- curlGetString "https://wttr.in?format=j2" [] |