Skip to content

Instantly share code, notes, and snippets.

@master-q
Created January 5, 2012 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save master-q/1564753 to your computer and use it in GitHub Desktop.
Save master-q/1564753 to your computer and use it in GitHub Desktop.
GetAllPagePan1.hs
#!/usr/bin/env runhaskell
{-# Language OverloadedStrings #-}
import qualified Text.Pandoc as P
import System.Process
import System.Exit
import qualified System.IO.UTF8 as U8
import Data.ByteString.Char8 ()
findLink' :: [P.Inline] -> [(String, String)]
findLink' inlines = concat $ fmap go inlines
where
go :: P.Inline -> [(String, String)]
go (P.Link [P.Str title] (url, _)) = [(url, title)]
go _ = []
findLink :: [P.Block] -> [(String, String)]
findLink blocks = concat $ fmap go blocks
where
go :: P.Block -> [(String, String)]
go (P.Plain inlines) = findLink' inlines
go (P.Para inlines) = findLink' inlines
go (P.BulletList blockss) = concat $ fmap findLink blockss
go _ = []
htmlToPandoc :: String -> P.Pandoc
htmlToPandoc = P.readHtml P.defaultParserState{ P.stateStandalone = True }
curlIt :: (String, String) -> IO ExitCode
curlIt ss = rawSystem "echo" ["curl -d p=\"" ++ postp ++
"\" -d c=e http://www.sampou.org/cgi-bin/haskell.cgi -o \""
++ outfile ++ "\""]
where postp = dropWhile (/= '?') $ fst ss
outfile = (snd ss) ++ ".html"
{--
curlIt :: (String, String) -> IO ExitCode
curlIt ss = system ("echo curl -d p=\"" ++ postp ++
"\" -d c=e http://www.sampou.org/cgi-bin/haskell.cgi -o \""
++ outfile ++ "\"")
where postp = tail . init $ dropWhile (/= '?') $ fst ss
outfile = (tail . init $ snd ss) ++ ".html"
--}
main :: IO ()
main = do
con <- getContents
let P.Pandoc _ blocks = htmlToPandoc con
print $ findLink blocks
mapM_ curlIt $ findLink blocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment