Skip to content

Instantly share code, notes, and snippets.

@dogweather
Last active August 8, 2016 22:54
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 dogweather/a5176a48eca597fa31064e146ef85ad9 to your computer and use it in GitHub Desktop.
Save dogweather/a5176a48eca597fa31064e146ef85ad9 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE UnicodeSyntax #-}
module Main where
import Data.Aeson
import Data.Aeson.Encode.Pretty
import Data.ByteString.Lazy (putStr)
import Data.List (isPrefixOf)
import Data.Maybe (fromMaybe)
import GHC.Generics
import Prelude.Unicode
import System.Environment (getArgs)
import Text.HandsomeSoup
import Text.XML.HXT.Core
data Amendment =
Amendment {
summary ∷ String,
text ∷ [String]
} deriving (Show, Generic)
instance ToJSON Amendment
main ∷ IO ()
main = do
html ← getContents
let amendment = newAmendment html
Data.ByteString.Lazy.putStr (encodePretty amendment)
newAmendment ∷ String → Amendment
newAmendment html =
Amendment {
summary = fromMaybe "No summary found" (findSummary (paragraphs html)),
text = paragraphs html
}
paragraphs ∷ String → [String]
paragraphs html =
runLA (hread >>> css "p" //> getText) html
findSummary ∷ [String] → Maybe String
findSummary text =
case filter isSummary text of
[x] → Just x
_ → Nothing
isSummary ∷ String → Bool
isSummary sentence =
"Relating to" `isPrefixOf` sentence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment