From 0a4d3c8f12dc5797a919a00b6bcaf759947687cc Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 17 Jun 2018 23:24:47 +0200 Subject: Add ouest france parser --- src/executable/haskell/Conf.hs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/executable/haskell/Conf.hs (limited to 'src/executable/haskell/Conf.hs') diff --git a/src/executable/haskell/Conf.hs b/src/executable/haskell/Conf.hs new file mode 100644 index 0000000..e59f2a7 --- /dev/null +++ b/src/executable/haskell/Conf.hs @@ -0,0 +1,39 @@ +{-# LANGUAGE OverloadedStrings #-} + +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] + , mailFrom :: Text + , mailTo :: [Text] + , listenInterval :: NominalDiffTime + , devMode :: Bool + } 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 "mailFrom" conf <*> + Conf.lookup "mailTo" conf <*> + Conf.lookup "listenInterval" conf <*> + Conf.lookup "devMode" conf + ) + case conf of + Left msg -> error (T.unpack msg) + Right c -> return c -- cgit v1.2.3