Last active
August 8, 2016 22:54
-
-
Save dogweather/a5176a48eca597fa31064e146ef85ad9 to your computer and use it in GitHub Desktop.
This file contains 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
{-# 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