-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.hs
48 lines (35 loc) · 2.15 KB
/
Config.hs
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
module Config where
import Data.Configurator(load,require,Worth(Required))
import Data.Configurator.Types as C
import Data.Text(unpack,pack)
import Data.Maybe(fromJust,fromMaybe)
import Network.URI
import Transforms
import Types as T
configure::FilePath -> IO T.Config
configure path = do
cfg <- load[Required path]
cache <- require cfg "cache" :: IO FilePath
output <-require cfg "output" :: IO FilePath
feedNames <- require cfg "feeds" :: IO [String]
feeds <- mapM (getFeed cfg) feedNames
return T.Config{feeds = feeds, cache = cache, rssStore = output}
getFeed::C.Config -> String -> IO Feed
getFeed cfg feed = do
url <- require cfg (pack (feed++".url")) :: IO String
let uri = fromMaybe (error (feed ++ ".url is not a valid url :-("))
(parseURI url)
transformNames <- require cfg (pack $ feed++".transforms") :: IO [String]
transforms <- mapM (\t -> case t of
"fetchfull" -> return fetchfull
"regexsnip" -> do
start_re <- require cfg (pack $ feed++".regexsnip.start_re") :: IO String
end_re <- require cfg (pack $ feed++".regexsnip.end_re") :: IO String
return (regexsnip start_re end_re)
_ -> error "Unknown transform?"
) transformNames
--use a maybe, get rid of warning
return Feed{name = feed, items = [], feedurl = url, transforms = transforms}
instance C.Configured [String] where
convert (C.List vals) = Just $ map (fromJust . fmap unpack . convert) vals
convert _ = Nothing