aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/AdListener.hs35
-rw-r--r--src/Main.hs2
-rw-r--r--src/Model/Resume.hs5
3 files changed, 26 insertions, 16 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)
diff --git a/src/Main.hs b/src/Main.hs
index ad70402..f38646b 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -16,6 +16,6 @@ main = do
maybeConfig <- C.getConfig
case maybeConfig of
Just config ->
- listenToNewAds config []
+ listenToNewAds config
Nothing ->
T.putStrLn C.configUsage
diff --git a/src/Model/Resume.hs b/src/Model/Resume.hs
index 3d307f2..46d07a1 100644
--- a/src/Model/Resume.hs
+++ b/src/Model/Resume.hs
@@ -16,10 +16,11 @@ data Resume = Resume
, url :: URL
} deriving (Eq, Read, Show)
-getNewResumes :: [URL] -> [Resume] -> [Resume]
+getNewResumes :: [URL] -> [Resume] -> ([URL], [Resume])
getNewResumes viewdURLs resumes =
let newURLs = (getURLs resumes) \\ viewdURLs
- in filter (\resume -> elem (url resume) newURLs) resumes
+ newResumes = filter (\resume -> elem (url resume) newURLs) resumes
+ in (newURLs, newResumes)
getURLs :: [Resume] -> [URL]
getURLs = map url