Created
January 5, 2012 11:05
-
-
Save master-q/1564762 to your computer and use it in GitHub Desktop.
GetAllPagePan2.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 () | |
curlIt ss = putStrLn ("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