diff options
author | Joris | 2018-06-17 23:24:47 +0200 |
---|---|---|
committer | Joris | 2018-06-18 11:13:55 +0200 |
commit | 0a4d3c8f12dc5797a919a00b6bcaf759947687cc (patch) | |
tree | bcb89781e22c2314bf0c064ebb37cb7f8a362f5c /src/AdListener.hs | |
parent | e2a5c7c5c596d057b6fa9c08a8204ce1429cfdc4 (diff) | |
download | ad-listener-0a4d3c8f12dc5797a919a00b6bcaf759947687cc.tar.gz ad-listener-0a4d3c8f12dc5797a919a00b6bcaf759947687cc.tar.bz2 ad-listener-0a4d3c8f12dc5797a919a00b6bcaf759947687cc.zip |
Add ouest france parser
Diffstat (limited to 'src/AdListener.hs')
-rw-r--r-- | src/AdListener.hs | 67 |
1 files changed, 0 insertions, 67 deletions
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 |