diff options
Diffstat (limited to 'src/executable/haskell/Service')
-rw-r--r-- | src/executable/haskell/Service/AdListener.hs | 59 |
1 files changed, 15 insertions, 44 deletions
diff --git a/src/executable/haskell/Service/AdListener.hs b/src/executable/haskell/Service/AdListener.hs index f0adbb8..bbd06d9 100644 --- a/src/executable/haskell/Service/AdListener.hs +++ b/src/executable/haskell/Service/AdListener.hs @@ -2,25 +2,20 @@ module Service.AdListener ( start ) where -import Control.Concurrent (threadDelay) -import Data.Either (rights) -import Data.Text.Encoding as T -import qualified Data.Text.IO as T -import Prelude hiding (error) +import Control.Concurrent (threadDelay) +import qualified Data.Text.IO as T +import Prelude hiding (error) -import Conf (Conf) +import Conf (Conf) import qualified Conf -import Model.Ad (Ad) -import qualified Model.Ad as Ad -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 -import qualified View.Ad as Ad +import qualified FetchAd +import Model.Ad (Ad) +import qualified Model.Ad as Ad +import Model.Mail (Mail (Mail)) +import Model.URL (URL) +import qualified Service.MailService as MailService +import qualified Utils.Time as TimeUtils +import qualified View.Ad as Ad start :: Conf -> IO () start conf = do @@ -49,39 +44,15 @@ listenToNewAdsWithViewedURLs conf viewedURLs = do fetchAds :: Conf -> IO [Ad] fetchAds conf = do - leboncoinAds <- getLeboncoinAds conf - ouestFranceAds <- getOuestFranceAds conf - seLogerAds <- getSeLogerAds conf + leboncoinAds <- FetchAd.leboncoin (Conf.leboncoinUrls conf) + ouestFranceAds <- FetchAd.ouestFrance (Conf.ouestFranceUrls conf) + seLogerAds <- FetchAd.seLoger (Conf.seLogerUrls conf) let results = leboncoinAds ++ ouestFranceAds ++ seLogerAds if null results then T.putStrLn "Parsed 0 results!" else return () return results -getLeboncoinAds :: Conf -> IO [Ad] -getLeboncoinAds conf = - fmap (concat . map LeboncoinParser.parse . rights) - . sequence - . map (HTTP.get T.decodeLatin1) - . Conf.leboncoinUrls - $ conf - -getOuestFranceAds :: Conf -> IO [Ad] -getOuestFranceAds conf = - fmap (concat . map OuestFranceParser.parse . rights) - . sequence - . map (HTTP.get T.decodeUtf8) - . 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 |