module Network.Shpider.State
( module Control.Monad.State
, ShpiderState (..)
, Page (..)
, Shpider
, emptyPage
, runShpider
, runShpiderSt
)
where
import Control.Monad.State
import Network.Shpider.Curl.Curl
import Data.Maybe
import Text.HTML.TagSoup.Parsec
import Network.Shpider.Forms
import Network.Shpider.Links
data ShpiderState =
SS { htmlOnlyDownloads :: Bool
, startPage :: String
, dontLeaveDomain :: Bool
, curlOpts :: [ CurlOption ]
, currentPage :: Page
, visited :: Maybe [ String ]
}
deriving Show
type Shpider =
StateT ShpiderState IO
runShpiderSt :: Shpider a -> IO ( a , ShpiderState )
runShpiderSt f =
withCurlDo $ runStateT f initialSt
runShpider :: Shpider a -> IO a
runShpider f = do
( res , _ ) <- runShpiderSt f
return res
initialSt :: ShpiderState
initialSt =
SS { startPage = ""
, htmlOnlyDownloads = False
, dontLeaveDomain = False
, curlOpts = [ CurlTimeout 3
, CurlCookieFile "cookies"
, CurlCookieJar "cookies"
]
, currentPage = emptyPage
, visited = Nothing
}
data Page =
Page { links :: [ Link ]
, forms :: [ Form ]
, tags :: [ Tag ]
, source :: String
, addr :: String
}
deriving Show
emptyPage :: Page
emptyPage =
Page { links = []
, forms = []
, source = ""
, tags = []
, addr =""
}