diff options
author | Joris | 2019-09-03 23:25:39 +0200 |
---|---|---|
committer | Joris | 2019-09-03 23:25:39 +0200 |
commit | 223ae6aa0b14c071d5719ada0cc6b43e9199a81b (patch) | |
tree | 6fc822b7b9bde1989e3c040eb52e5f4d52c49923 /src/executable | |
parent | 5cedcecd6ae31e2485dcab2ddd74c74a4779545d (diff) |
Use wreq instead of http-conduit to maintain cookies in a session
Diffstat (limited to 'src/executable')
-rw-r--r-- | src/executable/haskell/Main.hs | 6 | ||||
-rw-r--r-- | src/executable/haskell/Service/AdListener.hs | 28 |
2 files changed, 17 insertions, 17 deletions
diff --git a/src/executable/haskell/Main.hs b/src/executable/haskell/Main.hs index d082b94..8c0f37f 100644 --- a/src/executable/haskell/Main.hs +++ b/src/executable/haskell/Main.hs @@ -2,7 +2,7 @@ module Main ( main ) where -import qualified Network.HTTP.Conduit as H +import qualified Network.Wreq.Session as Session import qualified Conf import qualified Service.AdListener as AdListener @@ -10,5 +10,5 @@ import qualified Service.AdListener as AdListener main :: IO () main = do conf <- Conf.parse "application.conf" - manager <- H.newManager H.tlsManagerSettings - AdListener.start conf manager + session <- Session.newSession + AdListener.start conf session diff --git a/src/executable/haskell/Service/AdListener.hs b/src/executable/haskell/Service/AdListener.hs index 5cf26d1..c393f38 100644 --- a/src/executable/haskell/Service/AdListener.hs +++ b/src/executable/haskell/Service/AdListener.hs @@ -5,7 +5,7 @@ module Service.AdListener import Control.Concurrent (threadDelay) import qualified Data.Text as T import qualified Data.Text.IO as T -import Network.HTTP.Conduit (Manager) +import Network.Wreq.Session (Session) import Prelude hiding (error) import Conf (Conf) @@ -19,17 +19,17 @@ import qualified Service.MailService as MailService import qualified Utils.Time as TimeUtils import qualified View.Ad as Ad -start :: Conf -> Manager -> IO () -start conf manager = do - ads <- fetchAds conf manager +start :: Conf -> Session -> IO () +start conf session = do + ads <- fetchAds conf session let newURLs = map Ad.url ads T.putStrLn "Listening to new ads…" waitListenInterval conf - listenToNewAdsWithViewedURLs conf manager newURLs + listenToNewAdsWithViewedURLs conf session newURLs -listenToNewAdsWithViewedURLs :: Conf -> Manager -> [URL] -> IO () -listenToNewAdsWithViewedURLs conf manager viewedURLs = do - ads <- fetchAds conf manager +listenToNewAdsWithViewedURLs :: Conf -> Session -> [URL] -> IO () +listenToNewAdsWithViewedURLs conf session viewedURLs = do + ads <- fetchAds conf session let (newURLs, newAds) = Ad.getNewAds viewedURLs ads time <- TimeUtils.getCurrentFormattedTime if not (null newAds) @@ -40,13 +40,13 @@ listenToNewAdsWithViewedURLs conf manager viewedURLs = do else return () waitListenInterval conf - listenToNewAdsWithViewedURLs conf manager (viewedURLs ++ newURLs) + listenToNewAdsWithViewedURLs conf session (viewedURLs ++ newURLs) -fetchAds :: Conf -> Manager -> IO [Ad] -fetchAds conf manager = do - leboncoinAds <- FetchAd.leboncoin manager (Conf.leboncoinUrls conf) - ouestFranceAds <- FetchAd.ouestFrance manager (Conf.ouestFranceUrls conf) - seLogerAds <- FetchAd.seLoger manager (Conf.seLogerUrls conf) +fetchAds :: Conf -> Session -> IO [Ad] +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 T.putStrLn . T.concat $ [ "Parsed " |