diff options
author | Joris Guyonvarch | 2015-04-12 22:46:56 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-04-12 22:47:27 +0200 |
commit | 10a9aa9391ac2995527557d9d808693b57236603 (patch) | |
tree | d1aae79b86a7d289b5733519683302c712fe96da /src | |
parent | 293fab1df23821b5f131603c4db56ab71681ce59 (diff) |
Ignore lines beginning with # in the configuration file
Diffstat (limited to 'src')
-rw-r--r-- | src/Ad.hs | 18 | ||||
-rw-r--r-- | src/AdListener.hs | 12 | ||||
-rw-r--r-- | src/Config.hs | 3 | ||||
-rw-r--r-- | src/Utils/Text.hs | 13 |
4 files changed, 32 insertions, 14 deletions
@@ -1,6 +1,6 @@ module Ad - ( getResumes - , getAds + ( fetchResumes + , fetchAds ) where import Data.Text (Text) @@ -16,15 +16,15 @@ import Model.URL import Parser.Resume import Parser.Detail -getResumes :: URL -> IO (Either Text [Resume]) -getResumes url = fmap parseResumes <$> getPage url +fetchResumes :: URL -> IO (Either Text [Resume]) +fetchResumes url = fmap parseResumes <$> getPage url -getAds :: [Resume] -> IO (Either Text [Ad]) -getAds resumes = do - xs <- sequence $ map getAd resumes +fetchAds :: [Resume] -> IO (Either Text [Ad]) +fetchAds resumes = do + xs <- sequence $ map fetchAd resumes return $ sequence xs -getAd :: Resume -> IO (Either Text Ad) -getAd resume = do +fetchAd :: Resume -> IO (Either Text Ad) +fetchAd resume = do page <- getPage (url resume) fmap (\page -> Ad { resume = resume, detail = parseDetail page}) <$> getPage (url resume) diff --git a/src/AdListener.hs b/src/AdListener.hs index d676b61..dbd7a71 100644 --- a/src/AdListener.hs +++ b/src/AdListener.hs @@ -11,7 +11,7 @@ import qualified Data.Text.IO as T import Control.Concurrent (threadDelay) -import Ad (getResumes, getAds) +import Ad (fetchResumes, fetchAds) import Model.Ad import Model.URL @@ -27,7 +27,7 @@ import qualified Config as C listenToNewAds :: Config -> IO () listenToNewAds config = do - eitherResumes <- getResumes (C.url config) + eitherResumes <- fetchResumes (C.url config) case eitherResumes of Left error -> listenError config [] error @@ -37,7 +37,7 @@ listenToNewAds config = do listenToNewAdsWithViewedURLs :: Config -> [URL] -> IO () listenToNewAdsWithViewedURLs config viewedURLs = do - eitherResumes <- getResumes (C.url config) + eitherResumes <- fetchResumes (C.url config) case eitherResumes of Left error -> listenError config viewedURLs error @@ -48,7 +48,7 @@ listenToNewAdsWithResumes :: Config -> [URL] -> [Resume] -> IO () listenToNewAdsWithResumes config viewedURLs resumes = let (newURLs, newResumes) = getNewResumes viewedURLs resumes in do - eitherNewAds <- getAds newResumes + eitherNewAds <- fetchAds newResumes case eitherNewAds of Left error -> listenError config viewedURLs error @@ -68,7 +68,9 @@ newAdsMessage newAds = T.concat [ "Got " , T.pack . show . length $ newAds - , " new ads." + , " new ad" + , if length newAds > 1 then "s" else "" + , "." ] line = T.map (\_ -> '-') newAdsMessage in T.intercalate diff --git a/src/Config.hs b/src/Config.hs index c0b0bc0..7a44ec0 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -19,6 +19,8 @@ import System.Directory (doesFileExist) import Model.URL +import Utils.Text + configUsage :: Text configUsage = T.intercalate @@ -53,6 +55,7 @@ configFromFile = . catMaybes . map lineConfig . filter (not . T.null) + . filter (not . startsWith "#") . map T.strip . T.lines diff --git a/src/Utils/Text.hs b/src/Utils/Text.hs new file mode 100644 index 0000000..1297bbd --- /dev/null +++ b/src/Utils/Text.hs @@ -0,0 +1,13 @@ +module Utils.Text + ( startsWith + ) where + +import Data.Text (Text) +import qualified Data.Text as T + +startsWith :: Text -> Text -> Bool +startsWith mbStart text = + case (T.uncons mbStart, T.uncons text) of + (Just (x, xs), Just (y, ys)) -> x == y && startsWith xs ys + (Nothing, _) -> True + _ -> False |