module Conf ( parse , Conf(..) ) where import qualified Control.Logging as Logging import qualified Data.ConfigManager as Conf import Data.Text (Text) import qualified Data.Text as T import Data.Time.Clock (DiffTime) import Model.URL data Conf = Conf { leboncoinUrls :: [URL] , ouestFranceUrls :: [URL] , seLogerUrls :: [URL] , mailFrom :: Text , mailTo :: [Text] , mailMock :: Bool , listenFrom :: DiffTime , listenTo :: DiffTime , listenInterval :: DiffTime , listenIntervalNoise :: DiffTime , logLevel :: Logging.LogLevel } 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 "listenFrom" conf <*> Conf.lookup "listenTo" conf <*> Conf.lookup "listenInterval" conf <*> Conf.lookup "listenIntervalNoise" conf <*> Conf.lookup "logLevel" conf ) case conf of Left msg -> error (T.unpack msg) Right c -> return c