Commit f0a8c2e6 authored by Mudada's avatar Mudada

create / delete directory

parent a51250b8
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
module Main where module Main where
import SEARX import SEARX
import System.Directory
main :: IO () main :: IO ()
main = do main = do
...@@ -10,5 +11,7 @@ main = do ...@@ -10,5 +11,7 @@ main = do
case res of case res of
(Left err) -> print err (Left err) -> print err
(Right r) -> do (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" fp <- setUpDirectory
print a article <- parseWebsite fp "https://www.lemonde.fr/politique/article/2019/10/07/apres-l-attentat-a-la-prefecture-de-police-christophe-castaner-sous-le-feu-des-critiques_6014514_823448.html"
removeDirectoryRecursive $ fp <> "/readability"
print article
...@@ -50,14 +50,23 @@ data Article = ...@@ -50,14 +50,23 @@ data Article =
} }
deriving (Generic, Show, FromJSON, ToJSON) deriving (Generic, Show, FromJSON, ToJSON)
parseWebsite :: T.Text -> IO Article setUpDirectory :: IO FilePath
parseWebsite url = setUpDirectory =
withSystemTempDirectory "" $ \tmpdir -> do do
withCurrentDirectory tmpdir $ dir <- getCurrentDirectory
_ <- withCurrentDirectory dir $
traverse_ traverse_
callCommand callCommand
["npm init --yes", "npm install --save jsdom request-promise-native", [ "npm init --yes"
"git clone https://github.com/mozilla/readability.git"] , "npm install --save jsdom request-promise-native"
, "git clone https://github.com/mozilla/readability.git"
]
getCurrentDirectory
parseWebsite :: FilePath -> T.Text -> IO Article
parseWebsite tmpdir url =
do
withJSSession withJSSession
defJSSessionOpts {nodeWorkDir = Just tmpdir} defJSSessionOpts {nodeWorkDir = Just tmpdir}
[block| [block|
......
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