aboutsummaryrefslogtreecommitdiff
path: root/src/executable/haskell/Service
diff options
context:
space:
mode:
Diffstat (limited to 'src/executable/haskell/Service')
-rw-r--r--src/executable/haskell/Service/AdListener.hs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/executable/haskell/Service/AdListener.hs b/src/executable/haskell/Service/AdListener.hs
index 8a66404..1025166 100644
--- a/src/executable/haskell/Service/AdListener.hs
+++ b/src/executable/haskell/Service/AdListener.hs
@@ -4,6 +4,7 @@ module Service.AdListener
import Control.Concurrent (threadDelay)
import Data.Either (rights)
+import Data.Text.Encoding as T
import qualified Data.Text.IO as T
import Prelude hiding (error)
@@ -47,14 +48,30 @@ listenToNewAdsWithViewedURLs conf viewedURLs = do
fetchAds :: Conf -> IO [Ad]
fetchAds conf = do
- leboncoinAds <- fmap (concat . map LeboncoinParser.parse . rights) . sequence . map HTTP.get . Conf.leboncoinUrls $ conf
- ouestFranceAds <- fmap (concat . map OuestFranceParser.parse . rights) . sequence . map HTTP.get . Conf.ouestFranceUrls $ conf
+ leboncoinAds <- getLeboncoinAds conf
+ ouestFranceAds <- getOuestFranceAds conf
let results = leboncoinAds ++ ouestFranceAds
if null results
then T.putStrLn "Parsed 0 results!"
else return ()
return results
+getLeboncoinAds :: Conf -> IO [Ad]
+getLeboncoinAds conf =
+ fmap (concat . map LeboncoinParser.parse . rights)
+ . sequence
+ . map (HTTP.get T.decodeLatin1)
+ . Conf.leboncoinUrls
+ $ conf
+
+getOuestFranceAds :: Conf -> IO [Ad]
+getOuestFranceAds conf =
+ fmap (concat . map OuestFranceParser.parse . rights)
+ . sequence
+ . map (HTTP.get T.decodeUtf8)
+ . Conf.ouestFranceUrls
+ $ conf
+
sendMail :: Conf -> [Ad] -> IO ()
sendMail conf ads =
let (title, plainBody) = Ad.renderAds ads