From 0a4d3c8f12dc5797a919a00b6bcaf759947687cc Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 17 Jun 2018 23:24:47 +0200 Subject: Add ouest france parser --- src/AdListener.hs | 67 ------------------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 src/AdListener.hs (limited to 'src/AdListener.hs') diff --git a/src/AdListener.hs b/src/AdListener.hs deleted file mode 100644 index d8400d8..0000000 --- a/src/AdListener.hs +++ /dev/null @@ -1,67 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module AdListener - ( start - ) where - -import Prelude hiding (error) - -import qualified Data.Text.IO as T - -import Control.Concurrent (threadDelay) - -import qualified Fetch - -import Model.Ad -import Model.URL -import Model.Resume - -import qualified View.Plain.Ad as P -import qualified View.Html.Ad as H - -import Mail -import Model.Mail (Mail(Mail)) - -import Conf (Conf) -import qualified Conf - -import Time (getCurrentFormattedTime) - -start :: Conf -> IO () -start conf = do - resumes <- Fetch.resumes . Conf.urls $ conf - let newURLs = map url resumes - T.putStrLn "Listening to new ads…" - waitListenInterval conf - listenToNewAdsWithViewedURLs conf newURLs - -listenToNewAdsWithViewedURLs :: Conf -> [URL] -> IO () -listenToNewAdsWithViewedURLs conf viewedURLs = do - resumes <- Fetch.resumes . Conf.urls $ conf - let (newURLs, newResumes) = getNewResumes viewedURLs resumes - eitherNewAds <- Fetch.ads newResumes - case eitherNewAds of - Left error -> do - T.putStrLn error - waitListenInterval conf - listenToNewAdsWithViewedURLs conf viewedURLs - Right newAds -> do - time <- getCurrentFormattedTime - if not (null newAds) - then - let message = P.renderConsoleAds conf time newAds - in T.putStrLn message >> sendMail conf newAds - else - return () - waitListenInterval conf - listenToNewAdsWithViewedURLs conf (viewedURLs ++ newURLs) - -sendMail :: Conf -> [Ad] -> IO () -sendMail conf ads = - let (title, plainBody) = P.renderAds conf ads - htmlBody = H.renderAds conf ads - mail = Mail (Conf.mailFrom conf) (Conf.mailTo conf) title plainBody htmlBody - in Mail.send mail >> return () - -waitListenInterval :: Conf -> IO () -waitListenInterval = threadDelay . (*) 1000000 . round . Conf.listenInterval -- cgit v1.2.3