aboutsummaryrefslogtreecommitdiff
path: root/src/executable/haskell/Conf.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/executable/haskell/Conf.hs')
-rw-r--r--src/executable/haskell/Conf.hs39
1 files changed, 39 insertions, 0 deletions
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