From d14e302b9acf5164e04d8dfcd4dbd0aa1da48438 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 18 Jun 2018 11:31:22 +0200 Subject: Use default OverloadedStrings extension --- src/parser/haskell/Parser/LeboncoinParser.hs | 8 ++++---- src/parser/haskell/Parser/OuestFranceParser.hs | 8 +++----- src/parser/haskell/Parser/Utils.hs | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src/parser/haskell') diff --git a/src/parser/haskell/Parser/LeboncoinParser.hs b/src/parser/haskell/Parser/LeboncoinParser.hs index 48eb80f..77213cb 100644 --- a/src/parser/haskell/Parser/LeboncoinParser.hs +++ b/src/parser/haskell/Parser/LeboncoinParser.hs @@ -12,13 +12,13 @@ import Parser.Utils parse :: Text -> [Ad] parse page = - catMaybes . fmap parseAd $ partitions (~== "") tags + catMaybes . fmap parseAd $ partitions (~== (T.unpack "")) tags where tags = getTagsBetween "
  • " "
    " (parseTags page) parseAd :: [Tag Text] -> Maybe Ad parseAd tags = do name <- getTagTextAfter "

    " tags - location <- getTagAttribute "" (T.pack "content") tags + location <- getTagAttribute "" "content" tags let price = getTagTextAfter "

    " tags - url <- getTagAttribute "" (T.pack "href") tags - return (Ad name location price (T.concat [T.pack "https:", url])) + url <- getTagAttribute "" "href" tags + return (Ad name location price (T.concat ["https:", url])) diff --git a/src/parser/haskell/Parser/OuestFranceParser.hs b/src/parser/haskell/Parser/OuestFranceParser.hs index a7b6360..f46ed03 100644 --- a/src/parser/haskell/Parser/OuestFranceParser.hs +++ b/src/parser/haskell/Parser/OuestFranceParser.hs @@ -5,16 +5,14 @@ module Parser.OuestFranceParser import Data.Maybe (catMaybes) import Data.Text (Text) import qualified Data.Text as T - import Text.HTML.TagSoup import Model.Ad (Ad (Ad)) - import Parser.Utils parse :: Text -> [Ad] parse page = - catMaybes . fmap parseAd $ partitions (~== "") tags + catMaybes . fmap parseAd $ partitions (~== (T.unpack "")) tags where tags = getTagsBetween "
    " "
    " (parseTags page) parseAd :: [Tag Text] -> Maybe Ad @@ -22,6 +20,6 @@ parseAd tags = do name <- getTagTextAfter "" tags location <- getTagTextAfter "" tags let price = getTagTextAfter "" tags - let startUrl = T.pack "https://www.ouestfrance-immo.com/" - url <- getTagAttribute "" (T.pack "href") tags + let startUrl = "https://www.ouestfrance-immo.com/" + url <- getTagAttribute "" "href" tags return (Ad name location price (T.concat [startUrl, url])) diff --git a/src/parser/haskell/Parser/Utils.hs b/src/parser/haskell/Parser/Utils.hs index 7c433c6..461808d 100644 --- a/src/parser/haskell/Parser/Utils.hs +++ b/src/parser/haskell/Parser/Utils.hs @@ -14,29 +14,29 @@ import qualified Data.Text as T import Text.HTML.TagSoup -getTagsBefore :: String -> [Tag Text] -> [Tag Text] -getTagsBefore selector = takeWhile (~/= selector) +getTagsBefore :: Text -> [Tag Text] -> [Tag Text] +getTagsBefore selector = takeWhile (~/= (T.unpack selector)) -getTagsAfter :: String -> [Tag Text] -> [Tag Text] -getTagsAfter selector = drop 1 . dropWhile (~/= selector) +getTagsAfter :: Text -> [Tag Text] -> [Tag Text] +getTagsAfter selector = drop 1 . dropWhile (~/= (T.unpack selector)) -getTagsBetween :: String -> String -> [Tag Text] -> [Tag Text] +getTagsBetween :: Text -> Text -> [Tag Text] -> [Tag Text] getTagsBetween begin end = getTagsBefore end . getTagsAfter begin -getTagAttributes :: String -> Text -> [Tag Text] -> [Text] +getTagAttributes :: Text -> Text -> [Tag Text] -> [Text] getTagAttributes selector attribute = catMaybes . fmap (maybeTagAttribute attribute) - . filter (~== selector) + . filter (~== (T.unpack selector)) -getTagAttribute :: String -> Text -> [Tag Text] -> Maybe Text +getTagAttribute :: Text -> Text -> [Tag Text] -> Maybe Text getTagAttribute selector attribute = listToMaybe . getTagAttributes selector attribute -getTagTextAfter :: String -> [Tag Text] -> Maybe Text +getTagTextAfter :: Text -> [Tag Text] -> Maybe Text getTagTextAfter selector tags = - case findIndex (~== selector) tags of + case findIndex (~== (T.unpack selector)) tags of Just index -> fmap T.strip $ safeGetAt (index + 1) tags >>= maybeTagText Nothing -> Nothing -- cgit v1.2.3