diff options
author | Joris | 2018-06-17 23:24:47 +0200 |
---|---|---|
committer | Joris | 2018-06-18 11:13:55 +0200 |
commit | 0a4d3c8f12dc5797a919a00b6bcaf759947687cc (patch) | |
tree | bcb89781e22c2314bf0c064ebb37cb7f8a362f5c /src/executable/haskell/Utils | |
parent | e2a5c7c5c596d057b6fa9c08a8204ce1429cfdc4 (diff) |
Add ouest france parser
Diffstat (limited to 'src/executable/haskell/Utils')
-rw-r--r-- | src/executable/haskell/Utils/Either.hs | 7 | ||||
-rw-r--r-- | src/executable/haskell/Utils/HTTP.hs | 20 | ||||
-rw-r--r-- | src/executable/haskell/Utils/Text.hs | 13 | ||||
-rw-r--r-- | src/executable/haskell/Utils/Time.hs | 14 |
4 files changed, 54 insertions, 0 deletions
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) |