diff options
author | Joris | 2015-11-21 21:41:38 +0100 |
---|---|---|
committer | Joris | 2015-11-21 21:41:38 +0100 |
commit | 5375ad26dd78220185f1ffe05222250c06dc1a0c (patch) | |
tree | 30998d4fe19206e8c5c9e564db116d2022e5e313 /src/Model/Config.hs | |
parent | 7acd7a42f7663aa79d18e24bdb9fe19bf15f8fae (diff) |
Get next week birthdays and send an empty mail for the moment
Diffstat (limited to 'src/Model/Config.hs')
-rw-r--r-- | src/Model/Config.hs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Model/Config.hs b/src/Model/Config.hs new file mode 100644 index 0000000..b583048 --- /dev/null +++ b/src/Model/Config.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE FlexibleContexts #-} + +module Model.Config + ( getConfig + , Config(..) + ) where + +import Data.ConfigFile +import Data.Text (Text) +import qualified Data.Text as T + +import Control.Monad.Trans.Error (runErrorT) +import Control.Monad.IO.Class (liftIO) +import Control.Monad (join) +import Control.Arrow (left) + +data Config = Config + { mailTo :: Text + , mailFrom :: Text + , dayForNextWeekNotification :: Text + } deriving (Read, Eq, Show) + +getConfig :: FilePath -> IO (Either Text Config) +getConfig filePath = + left (T.pack . show) <$> (runErrorT $ do + cp <- join $ liftIO $ readfile emptyCP filePath + Config <$> + (T.pack <$> get cp "DEFAULT" "mail-to") <*> + (T.pack <$> get cp "DEFAULT" "mail-from") <*> + (T.pack <$> get cp "DEFAULT" "day-for-next-week-notification") + ) |