blob: 53a1046dbe02d2be9843635f750b36e737d6d8d0 (
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
40
41
42
43
44
45
46
47
48
|
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
|