module Conf ( parse , Conf(..) ) where import qualified Data.ConfigManager as Conf import Data.Text (Text) import qualified Data.Text as T import Data.Time.Clock (NominalDiffTime) import Model.URL data Conf = Conf { leboncoinUrls :: [URL] , ouestFranceUrls :: [URL] , seLogerUrls :: [URL] , mailFrom :: Text , mailTo :: [Text] , mailMock :: Bool , listenInterval :: NominalDiffTime } deriving Show parse :: FilePath -> IO Conf parse path = do conf <- (flip fmap) (Conf.readConfig path) (\configOrError -> do conf <- configOrError Conf <$> Conf.lookup "leboncoinUrls" conf <*> Conf.lookup "ouestFranceUrls" conf <*> Conf.lookup "seLogerUrls" conf <*> Conf.lookup "mailFrom" conf <*> Conf.lookup "mailTo" conf <*> Conf.lookup "mailMock" conf <*> Conf.lookup "listenInterval" conf ) case conf of Left msg -> error (T.unpack msg) Right c -> return c