diff options
author | Joris | 2018-06-18 11:31:22 +0200 |
---|---|---|
committer | Joris | 2018-06-18 11:31:22 +0200 |
commit | d14e302b9acf5164e04d8dfcd4dbd0aa1da48438 (patch) | |
tree | 6a3d343869acac65d4a11aa31fcae73a44f575a8 /src | |
parent | 0a4d3c8f12dc5797a919a00b6bcaf759947687cc (diff) |
Use default OverloadedStrings extension
Diffstat (limited to 'src')
-rw-r--r-- | src/executable/haskell/Conf.hs | 2 | ||||
-rw-r--r-- | src/executable/haskell/Main.hs | 2 | ||||
-rw-r--r-- | src/executable/haskell/Service/AdListener.hs | 2 | ||||
-rw-r--r-- | src/executable/haskell/Service/MailService.hs | 2 | ||||
-rw-r--r-- | src/executable/haskell/View/Ad.hs | 2 | ||||
-rw-r--r-- | src/parser/haskell/Parser/LeboncoinParser.hs | 8 | ||||
-rw-r--r-- | src/parser/haskell/Parser/OuestFranceParser.hs | 8 | ||||
-rw-r--r-- | src/parser/haskell/Parser/Utils.hs | 20 | ||||
-rw-r--r-- | src/test/haskell/Main.hs | 2 |
9 files changed, 17 insertions, 31 deletions
diff --git a/src/executable/haskell/Conf.hs b/src/executable/haskell/Conf.hs index e59f2a7..35064ca 100644 --- a/src/executable/haskell/Conf.hs +++ b/src/executable/haskell/Conf.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE OverloadedStrings #-} - module Conf ( parse , Conf(..) diff --git a/src/executable/haskell/Main.hs b/src/executable/haskell/Main.hs index b6705f9..fa1388c 100644 --- a/src/executable/haskell/Main.hs +++ b/src/executable/haskell/Main.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE OverloadedStrings #-} - module Main ( main ) where diff --git a/src/executable/haskell/Service/AdListener.hs b/src/executable/haskell/Service/AdListener.hs index f903f94..8a66404 100644 --- a/src/executable/haskell/Service/AdListener.hs +++ b/src/executable/haskell/Service/AdListener.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE OverloadedStrings #-} - module Service.AdListener ( start ) where diff --git a/src/executable/haskell/Service/MailService.hs b/src/executable/haskell/Service/MailService.hs index f6d9542..955dea1 100644 --- a/src/executable/haskell/Service/MailService.hs +++ b/src/executable/haskell/Service/MailService.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE OverloadedStrings #-} - module Service.MailService ( send ) where diff --git a/src/executable/haskell/View/Ad.hs b/src/executable/haskell/View/Ad.hs index ba0c550..1739386 100644 --- a/src/executable/haskell/View/Ad.hs +++ b/src/executable/haskell/View/Ad.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE OverloadedStrings #-} - module View.Ad ( renderConsoleAds , renderAds 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 (~== "<a>") tags + catMaybes . fmap parseAd $ partitions (~== (T.unpack "<a>")) tags where tags = getTagsBetween "<li itemtype=http://schema.org/Offer>" "<div class=information-immo_content>" (parseTags page) parseAd :: [Tag Text] -> Maybe Ad parseAd tags = do name <- getTagTextAfter "<h2 class=item_title>" tags - location <- getTagAttribute "<meta itemprop=address>" (T.pack "content") tags + location <- getTagAttribute "<meta itemprop=address>" "content" tags let price = getTagTextAfter "<h3 class=item_price>" tags - url <- getTagAttribute "<a>" (T.pack "href") tags - return (Ad name location price (T.concat [T.pack "https:", url])) + url <- getTagAttribute "<a>" "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 (~== "<a>") tags + catMaybes . fmap parseAd $ partitions (~== (T.unpack "<a>")) tags where tags = getTagsBetween "<div id=listAnnonces>" "<div id=interactions>" (parseTags page) parseAd :: [Tag Text] -> Maybe Ad @@ -22,6 +20,6 @@ parseAd tags = do name <- getTagTextAfter "<span class=annTitre>" tags location <- getTagTextAfter "<span class=annVille>" tags let price = getTagTextAfter "<span class=annPrix>" tags - let startUrl = T.pack "https://www.ouestfrance-immo.com/" - url <- getTagAttribute "<a>" (T.pack "href") tags + let startUrl = "https://www.ouestfrance-immo.com/" + url <- getTagAttribute "<a>" "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 diff --git a/src/test/haskell/Main.hs b/src/test/haskell/Main.hs index 6581d0f..fae0a63 100644 --- a/src/test/haskell/Main.hs +++ b/src/test/haskell/Main.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE OverloadedStrings #-} - import qualified Data.Text.IO as T import Test.Hspec |