aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--src/executable/haskell/Service/AdListener.hs21
2 files changed, 14 insertions, 8 deletions
diff --git a/README.md b/README.md
index ca0390d..cf16767 100644
--- a/README.md
+++ b/README.md
@@ -36,5 +36,6 @@ See [application.conf](application.conf).
## Ideas
+- add logging system
- add sqlite DB, to get back to previous state if shut down, it also permits to
see what has already been seen.
diff --git a/src/executable/haskell/Service/AdListener.hs b/src/executable/haskell/Service/AdListener.hs
index 5b4d634..9a9fc3d 100644
--- a/src/executable/haskell/Service/AdListener.hs
+++ b/src/executable/haskell/Service/AdListener.hs
@@ -21,8 +21,7 @@ import qualified View.Ad as Ad
start :: Conf -> Session -> IO ()
start conf session = do
- -- ads <- fetchAds conf session
- let ads = []
+ ads <- fetchAds conf session
let newURLs = map Ad.url ads
T.putStrLn "Listening to new ads…"
sleepUntilReady conf
@@ -48,13 +47,20 @@ fetchAds conf session = do
leboncoinAds <- FetchAd.leboncoin session (Conf.leboncoinUrls conf)
ouestFranceAds <- FetchAd.ouestFrance session (Conf.ouestFranceUrls conf)
seLogerAds <- FetchAd.seLoger session (Conf.seLogerUrls conf)
- let results = leboncoinAds ++ ouestFranceAds ++ seLogerAds
+ let ads = leboncoinAds ++ ouestFranceAds ++ seLogerAds
+ logFetchAds ads
+ return ads
+
+logFetchAds :: [Ad] -> IO ()
+logFetchAds ads = do
+ now <- TimeUtils.getCurrentFormattedTime
T.putStrLn . T.concat $
- [ "Parsed "
- , T.pack . show $ length results
- , " results"
+ [ "At "
+ , now
+ , ": fetched "
+ , T.pack . show $ length ads
+ , " ads"
]
- return results
sendMail :: Conf -> [Ad] -> IO ()
sendMail conf ads =
@@ -73,7 +79,6 @@ sleepUntilReady conf = do
Nothing -> do
duration <- TimeUtils.addNoise (Conf.listenInterval conf) (Conf.listenIntervalNoise conf)
- putStrLn . show $ duration
sleepSeconds duration
where
sleepSeconds =