aboutsummaryrefslogtreecommitdiff
path: root/src/AdListener.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/AdListener.hs')
-rw-r--r--src/AdListener.hs52
1 files changed, 17 insertions, 35 deletions
diff --git a/src/AdListener.hs b/src/AdListener.hs
index 04e070b..1de56dc 100644
--- a/src/AdListener.hs
+++ b/src/AdListener.hs
@@ -17,7 +17,7 @@ import Model.Ad
import Model.URL
import Model.Resume
-import View.Ad (renderAds)
+import View.Ad
import Page
import Parser.Detail
@@ -63,50 +63,32 @@ listenToNewAdsWithResumes config viewedURLs resumes =
time <- getCurrentFormattedTime
if not (null newAds)
then
- let message = newAdsMessage time newAds
+ let message = renderConsoleAds time newAds
in do
T.putStrLn message
- trySendMail config message
+ trySendMail config newAds
else
return ()
waitOneMinute
listenToNewAdsWithViewedURLs config (viewedURLs ++ newURLs)
-trySendMail :: Config -> Text -> IO ()
-trySendMail config message =
+trySendMail :: Config -> [Ad] -> IO ()
+trySendMail config ads =
case C.mailTo config of
- Just mailTo ->
- do
- eitherMailSuccess <- sendMail mailTo message
- case eitherMailSuccess of
- Right () ->
- putStrLn "Mail sent."
- Left error ->
- T.putStrLn . T.concat $
- [ "Error sending mail: "
- , error
- ]
Nothing ->
return ()
-
-newAdsMessage :: Text -> [Ad] -> Text
-newAdsMessage time newAds =
- let newAdsMessage =
- T.concat
- [ "\nAt "
- , time
- , ", got "
- , T.pack . show . length $ newAds
- , " new ad"
- , if length newAds > 1 then "s" else ""
- ]
- line = T.map (\_ -> '-') newAdsMessage
- in T.intercalate
- "\n"
- [ newAdsMessage
- , T.concat [line, "\n"]
- , renderAds newAds
- ]
+ Just mailTo ->
+ let (title, message) = renderAds ads
+ in do
+ eitherMailSuccess <- sendMail mailTo title message
+ case eitherMailSuccess of
+ Right () ->
+ putStrLn "\nMail sent."
+ Left error ->
+ T.putStrLn . T.concat $
+ [ "\nError sending mail: "
+ , error
+ ]
listenError :: Config -> [URL] -> Text -> IO ()
listenError config viewedURLs error = do