diff options
Diffstat (limited to 'src/AdListener.hs')
-rw-r--r-- | src/AdListener.hs | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/AdListener.hs b/src/AdListener.hs index 1f97e30..d676b61 100644 --- a/src/AdListener.hs +++ b/src/AdListener.hs @@ -25,24 +25,33 @@ import Parser.Detail import Config (Config) import qualified Config as C -listenToNewAds :: Config -> [Ad] -> IO () -listenToNewAds config viewedAds = do +listenToNewAds :: Config -> IO () +listenToNewAds config = do eitherResumes <- getResumes (C.url config) case eitherResumes of Left error -> - listenError config viewedAds error + listenError config [] error Right resumes -> - listenToNewAdsWithResumes config viewedAds resumes + let newURLs = map url resumes + in listenToNewAdsWithViewedURLs config newURLs -listenToNewAdsWithResumes :: Config -> [Ad] -> [Resume] -> IO () -listenToNewAdsWithResumes config viewedAds resumes = - let viewedURLs = getURLs $ map resume viewedAds - newResumes = getNewResumes viewedURLs resumes +listenToNewAdsWithViewedURLs :: Config -> [URL] -> IO () +listenToNewAdsWithViewedURLs config viewedURLs = do + eitherResumes <- getResumes (C.url config) + case eitherResumes of + Left error -> + listenError config viewedURLs error + Right resumes -> + listenToNewAdsWithResumes config viewedURLs resumes + +listenToNewAdsWithResumes :: Config -> [URL] -> [Resume] -> IO () +listenToNewAdsWithResumes config viewedURLs resumes = + let (newURLs, newResumes) = getNewResumes viewedURLs resumes in do eitherNewAds <- getAds newResumes case eitherNewAds of Left error -> - listenError config viewedAds error + listenError config viewedURLs error Right newAds -> do if not (null newAds) @@ -51,7 +60,7 @@ listenToNewAdsWithResumes config viewedAds resumes = else return () waitOneMinute - listenToNewAds config (viewedAds ++ newAds) + listenToNewAdsWithViewedURLs config (viewedURLs ++ newURLs) newAdsMessage :: [Ad] -> Text newAdsMessage newAds = @@ -69,11 +78,11 @@ newAdsMessage newAds = , renderAds newAds ] -listenError :: Config -> [Ad] -> Text -> IO () -listenError config viewedAds error = do +listenError :: Config -> [URL] -> Text -> IO () +listenError config viewedURLs error = do T.putStrLn error waitOneMinute - listenToNewAds config viewedAds + listenToNewAdsWithViewedURLs config viewedURLs waitOneMinute :: IO () waitOneMinute = threadDelay (1000 * 1000 * 60) |