aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--src/AdListener.hs27
-rw-r--r--src/Fetch.hs10
3 files changed, 22 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index 360ffe2..ab517c4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
-node_modules
dist
local.conf
leboncoin-listener.nix
diff --git a/src/AdListener.hs b/src/AdListener.hs
index 9946d9e..3db4c6a 100644
--- a/src/AdListener.hs
+++ b/src/AdListener.hs
@@ -38,7 +38,7 @@ start conf = do
showErrorAndListenBack conf [] error
Right resumes -> do
let newURLs = map url resumes
- putStrLn "Listening to new ads…"
+ T.putStrLn "Listening to new ads…"
waitListenInterval conf
listenToNewAdsWithViewedURLs conf newURLs
@@ -59,19 +59,18 @@ listenToNewAdsWithResumes conf viewedURLs resumes =
case eitherNewAds of
Left error ->
showErrorAndListenBack conf viewedURLs error
- Right newAds ->
- do
- time <- getCurrentFormattedTime
- if not (null newAds)
- then
- let message = P.renderConsoleAds conf time newAds
- in do
- T.putStrLn message
- trySendMail conf newAds
- else
- return ()
- waitListenInterval conf
- listenToNewAdsWithViewedURLs conf (viewedURLs ++ newURLs)
+ Right newAds -> do
+ time <- getCurrentFormattedTime
+ if not (null newAds)
+ then
+ let message = P.renderConsoleAds conf time newAds
+ in do
+ T.putStrLn message
+ trySendMail conf newAds
+ else
+ return ()
+ waitListenInterval conf
+ listenToNewAdsWithViewedURLs conf (viewedURLs ++ newURLs)
trySendMail :: Conf -> [Ad] -> IO ()
trySendMail conf ads =
diff --git a/src/Fetch.hs b/src/Fetch.hs
index c80a980..ea82caa 100644
--- a/src/Fetch.hs
+++ b/src/Fetch.hs
@@ -1,9 +1,12 @@
+{-# LANGUAGE OverloadedStrings #-}
+
module Fetch
( fetchResumes
, fetchAds
) where
import Data.Text (Text)
+import qualified Data.Text.IO as T
import Page
@@ -16,7 +19,12 @@ import qualified Parser.Resume as Resume
import qualified Parser.Detail as Detail
fetchResumes :: URL -> IO (Either Text [Resume])
-fetchResumes url = fmap Resume.parse <$> Page.get url
+fetchResumes url = do
+ resumes <- fmap Resume.parse <$> Page.get url
+ if null resumes
+ then T.putStrLn "Parsed 0 results!"
+ else return ()
+ return resumes
fetchAds :: [Resume] -> IO (Either Text [Ad])
fetchAds resumes = do