diff options
Diffstat (limited to 'src/AdListener.hs')
-rw-r--r-- | src/AdListener.hs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/AdListener.hs b/src/AdListener.hs index 21775cc..da3051d 100644 --- a/src/AdListener.hs +++ b/src/AdListener.hs @@ -22,6 +22,8 @@ import View.Ad (renderAds) import Page import Parser.Detail +import Mail (sendMail) + import Config (Config) import qualified Config as C @@ -35,7 +37,9 @@ listenToNewAds config = do listenError config [] error Right resumes -> let newURLs = map url resumes - in listenToNewAdsWithViewedURLs config newURLs + in do + putStrLn "Listening for new ads…" + listenToNewAdsWithViewedURLs config newURLs listenToNewAdsWithViewedURLs :: Config -> [URL] -> IO () listenToNewAdsWithViewedURLs config viewedURLs = do @@ -59,12 +63,32 @@ listenToNewAdsWithResumes config viewedURLs resumes = time <- getCurrentFormattedTime if not (null newAds) then - T.putStrLn (newAdsMessage time newAds) + let message = newAdsMessage time newAds + in do + T.putStrLn message + trySendMail config message else return () waitOneMinute listenToNewAdsWithViewedURLs config (viewedURLs ++ newURLs) +trySendMail :: Config -> Text -> IO () +trySendMail config message = + case C.mailTo config of + Just mailTo -> + do + eitherMailSuccess <- sendMail mailTo message + case eitherMailSuccess of + Right () -> + return "Mail sent." + Left error -> + T.putStrLn . T.concat $ + [ "Error sending mail: " + , error + ] + Nothing -> + return () + newAdsMessage :: Text -> [Ad] -> Text newAdsMessage time newAds = let newAdsMessage = |