diff options
author | Joris | 2018-06-18 23:15:12 +0200 |
---|---|---|
committer | Joris | 2018-06-18 23:15:12 +0200 |
commit | 318292532a877c308403c45795d229fad659d900 (patch) | |
tree | 16e4695cc316a28bff4f0a9ae42e779ecce82a31 /src/executable | |
parent | 96bbdbbe9b22b3c3e96998cc18a3b68c9db66da9 (diff) |
Add seLoger parser
Diffstat (limited to 'src/executable')
-rw-r--r-- | src/executable/haskell/Conf.hs | 2 | ||||
-rw-r--r-- | src/executable/haskell/Service/AdListener.hs | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/executable/haskell/Conf.hs b/src/executable/haskell/Conf.hs index 35064ca..e6bd4ca 100644 --- a/src/executable/haskell/Conf.hs +++ b/src/executable/haskell/Conf.hs @@ -13,6 +13,7 @@ import Model.URL data Conf = Conf { leboncoinUrls :: [URL] , ouestFranceUrls :: [URL] + , seLogerUrls :: [URL] , mailFrom :: Text , mailTo :: [Text] , listenInterval :: NominalDiffTime @@ -27,6 +28,7 @@ parse path = do Conf <$> Conf.lookup "leboncoinUrls" conf <*> Conf.lookup "ouestFranceUrls" conf <*> + Conf.lookup "seLogerUrls" conf <*> Conf.lookup "mailFrom" conf <*> Conf.lookup "mailTo" conf <*> Conf.lookup "listenInterval" conf <*> diff --git a/src/executable/haskell/Service/AdListener.hs b/src/executable/haskell/Service/AdListener.hs index 1025166..f0adbb8 100644 --- a/src/executable/haskell/Service/AdListener.hs +++ b/src/executable/haskell/Service/AdListener.hs @@ -16,6 +16,7 @@ import Model.Mail (Mail (Mail)) import Model.URL (URL) import qualified Parser.LeboncoinParser as LeboncoinParser import qualified Parser.OuestFranceParser as OuestFranceParser +import qualified Parser.SeLogerParser as SeLogerParser import qualified Service.MailService as MailService import qualified Utils.HTTP as HTTP import qualified Utils.Time as TimeUtils @@ -50,7 +51,8 @@ fetchAds :: Conf -> IO [Ad] fetchAds conf = do leboncoinAds <- getLeboncoinAds conf ouestFranceAds <- getOuestFranceAds conf - let results = leboncoinAds ++ ouestFranceAds + seLogerAds <- getSeLogerAds conf + let results = leboncoinAds ++ ouestFranceAds ++ seLogerAds if null results then T.putStrLn "Parsed 0 results!" else return () @@ -72,6 +74,14 @@ getOuestFranceAds conf = . Conf.ouestFranceUrls $ conf +getSeLogerAds :: Conf -> IO [Ad] +getSeLogerAds conf = + fmap (concat . map SeLogerParser.parse . rights) + . sequence + . map (HTTP.get T.decodeUtf8) + . Conf.seLogerUrls + $ conf + sendMail :: Conf -> [Ad] -> IO () sendMail conf ads = let (title, plainBody) = Ad.renderAds ads |