blob: e59f2a7b42779cca5f92994efa5e537dfabcb32c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
|