aboutsummaryrefslogtreecommitdiff
path: root/src/executable/haskell/Service
diff options
context:
space:
mode:
authorJoris2018-06-18 21:51:51 +0200
committerJoris2018-06-18 21:51:51 +0200
commit96bbdbbe9b22b3c3e96998cc18a3b68c9db66da9 (patch)
tree1a5e5e1b8d44c0a7dad614a1a0d5c7886a585d17 /src/executable/haskell/Service
parent3717598bb16a23097bbe1b4e676fd4e781eec640 (diff)
Fix ouest france ads encoding
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