From 96bbdbbe9b22b3c3e96998cc18a3b68c9db66da9 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 18 Jun 2018 21:51:51 +0200 Subject: Fix ouest france ads encoding --- src/executable/haskell/Service/AdListener.hs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/executable/haskell/Service') 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 -- cgit v1.2.3