Commit f1e873f0 authored by Mudada's avatar Mudada

add readability

parent 3cd592a2
[submodule "inline-js"]
path = inline-js
url = https://github.com/tweag/inline-js
...@@ -6,7 +6,9 @@ import SEARX ...@@ -6,7 +6,9 @@ import SEARX
main :: IO () main :: IO ()
main = do main = do
res <- getMetadataWith "ia" 300 res <- getMetadataWith "ia" 1
case res of case res of
(Left err) -> print err (Left err) -> print err
(Right r) -> print r (Right r) -> do
a <- parseWebsite "https://www.lemonde.fr/economie/article/2019/09/23/thomas-cook-semble-se-diriger-vers-une-faillite_6012630_3234.html"
print a
Subproject commit ad33fe42821d146a6dc8c18c4f31ee7ba27e3fa4
...@@ -28,6 +28,11 @@ dependencies: ...@@ -28,6 +28,11 @@ dependencies:
- servant-client - servant-client
- http-client - http-client
- http-client-tls - http-client-tls
- inline-js
- inline-js-core
- process
- directory
- temporary
library: library:
source-dirs: src source-dirs: src
......
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
module SEARX where module SEARX where
import Network.HTTP.Client (newManager) import Network.HTTP.Client (newManager)
import Network.HTTP.Client.TLS (tlsManagerSettings) import Network.HTTP.Client.TLS (tlsManagerSettings)
import Language.JavaScript.Inline
import System.Directory
import System.IO.Temp
import System.Process
import Servant.Client import Servant.Client
import SEARX.Client import SEARX.Client
import Data.Foldable
import qualified Data.Text as T import qualified Data.Text as T
{- {-
...@@ -20,6 +31,25 @@ getMetadataWith2 q = do ...@@ -20,6 +31,25 @@ getMetadataWith2 q = do
runClientM runClientM
(search (Just q) (Just 1) (Just 3) (Just "") (Just All) (Just Json)) (search (Just q) (Just 1) (Just 3) (Just "") (Just All) (Just Json))
(mkClientEnv manager' $ BaseUrl Https "search.iscpif.fr" 443 "") (mkClientEnv manager' $ BaseUrl Https "search.iscpif.fr" 443 "")
{--
read($url, function(err, article, meta) {
// Title
article.close();
-}
parseWebsite :: T.Text -> IO Int
parseWebsite url =
withSystemTempDirectory "" $ \tmpdir -> do
withCurrentDirectory tmpdir $
traverse_
callCommand
["npm init --yes", "npm install --save node-readability"]
withJSSession
defJSSessionOpts {nodeWorkDir = Just tmpdir}
[block|
return 12;
});
|]
specConcatEith :: Semigroup a => Either b a -> Either b a -> Either b a specConcatEith :: Semigroup a => Either b a -> Either b a -> Either b a
specConcatEith (Left _) b = b specConcatEith (Left _) b = b
......
...@@ -34,10 +34,13 @@ resolver: lts-14.4 ...@@ -34,10 +34,13 @@ resolver: lts-14.4
# - wai # - wai
packages: packages:
- . - .
# Dependency packages to be pulled from upstream that are not in the resolver # Dependency packages to be pulled from upstream that are not in the resolver
# using the same syntax as the packages field. # using the same syntax as the packages field.
# (e.g., acme-missiles-0.3) # (e.g., acme-missiles-0.3)
# extra-deps: [] extra-deps:
- ./inline-js/inline-js-core
- ./inline-js/inline-js
# Override default flag values for local packages and extra-deps # Override default flag values for local packages and extra-deps
# flags: {} # flags: {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment