From 0a4d3c8f12dc5797a919a00b6bcaf759947687cc Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 17 Jun 2018 23:24:47 +0200 Subject: Add ouest france parser --- src/executable/haskell/Utils/Either.hs | 7 +++++++ src/executable/haskell/Utils/HTTP.hs | 20 ++++++++++++++++++++ src/executable/haskell/Utils/Text.hs | 13 +++++++++++++ src/executable/haskell/Utils/Time.hs | 14 ++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 src/executable/haskell/Utils/Either.hs create mode 100644 src/executable/haskell/Utils/HTTP.hs create mode 100644 src/executable/haskell/Utils/Text.hs create mode 100644 src/executable/haskell/Utils/Time.hs (limited to 'src/executable/haskell/Utils') diff --git a/src/executable/haskell/Utils/Either.hs b/src/executable/haskell/Utils/Either.hs new file mode 100644 index 0000000..5d62dcc --- /dev/null +++ b/src/executable/haskell/Utils/Either.hs @@ -0,0 +1,7 @@ +module Utils.Either + ( mapLeft + ) where + +mapLeft :: (a -> c) -> Either a b -> Either c b +mapLeft f (Left l) = Left (f l) +mapLeft _ (Right r) = (Right r) diff --git a/src/executable/haskell/Utils/HTTP.hs b/src/executable/haskell/Utils/HTTP.hs new file mode 100644 index 0000000..c901500 --- /dev/null +++ b/src/executable/haskell/Utils/HTTP.hs @@ -0,0 +1,20 @@ +module Utils.HTTP + ( get + ) where + +import Control.Exception (SomeException, try) + +import Data.ByteString.Lazy as BS +import Data.Text (Text) +import qualified Data.Text as T +import Data.Text.Encoding as T +import Network.HTTP.Conduit + +import Model.URL +import Utils.Either (mapLeft) + +get :: URL -> IO (Either Text Text) +get url = mapLeft (T.pack . show) <$> (try (unsafeGetPage url) :: IO (Either SomeException Text)) + +unsafeGetPage :: URL -> IO Text +unsafeGetPage url = (T.decodeLatin1 . BS.toStrict) <$> simpleHttp (T.unpack url) diff --git a/src/executable/haskell/Utils/Text.hs b/src/executable/haskell/Utils/Text.hs new file mode 100644 index 0000000..1297bbd --- /dev/null +++ b/src/executable/haskell/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 diff --git a/src/executable/haskell/Utils/Time.hs b/src/executable/haskell/Utils/Time.hs new file mode 100644 index 0000000..b6045a7 --- /dev/null +++ b/src/executable/haskell/Utils/Time.hs @@ -0,0 +1,14 @@ +module Utils.Time + ( getCurrentFormattedTime + ) where + +import Data.Text (Text) +import qualified Data.Text as T + +import Data.Time.Format (defaultTimeLocale, formatTime) +import Data.Time.LocalTime (getZonedTime) + +getCurrentFormattedTime :: IO Text +getCurrentFormattedTime = do + zonedTime <- getZonedTime + return (T.pack $ formatTime defaultTimeLocale "%Hh%M" zonedTime) -- cgit v1.2.3