get tags for full definition
This commit is contained in:
parent
2d76314eaf
commit
221e5a60cf
3
Main.hs
3
Main.hs
@ -15,7 +15,8 @@ parse ("-d":[]) = usage
|
||||
parse ("-d":n:[]) = usage
|
||||
parse ("-d":n:fs) = do
|
||||
htmlResult <- downloadHtmlDef n (head fs)
|
||||
printDef (E.decodeUtf8 htmlResult)
|
||||
let n' = read n :: Int
|
||||
printDef (E.decodeUtf8 htmlResult) n'
|
||||
parse fs = do
|
||||
htmlResult <- downloadHtmlAvailableDef (head fs)
|
||||
printDifferentDef (E.decodeUtf8 htmlResult)
|
||||
|
30
ParseHtml.hs
30
ParseHtml.hs
@ -3,6 +3,7 @@ module ParseHtml (printDef, printDifferentDef) where
|
||||
import Text.HTML.TagSoup
|
||||
import Prelude
|
||||
import WordDef
|
||||
import qualified Data.List as L
|
||||
import qualified Data.Text.Lazy as T
|
||||
|
||||
|
||||
@ -37,17 +38,26 @@ differentDefTags =
|
||||
filter (~== TagText "") . (takeWhile (~/= "<div id=contentbox>"))
|
||||
. (dropWhile (~/= "<div id=vtoolbar>")) . parseTags . T.unpack
|
||||
|
||||
printDef :: T.Text -> IO ()
|
||||
printDef = putStrLn . getDef
|
||||
printDef :: T.Text -> Int -> IO ()
|
||||
printDef t n = putStrLn (getDef t n)
|
||||
|
||||
getDef :: T.Text -> String
|
||||
getDef = (renderFullDef . getFullDef . parseFullDefTags)
|
||||
getDef :: T.Text -> Int -> String
|
||||
getDef t n = renderFullDef (getFullDef t n)
|
||||
|
||||
getFullDef :: [Tag String] -> WordFullDef
|
||||
getFullDef x = WordFullDef (WordDefHeader (WordName "lol") (WordType
|
||||
"Interjection")) [WordDefSentence "Laughing Out Loud",
|
||||
WordExampleSentence "ur wrong lol"]
|
||||
getFullDef :: T.Text -> Int -> WordFullDef
|
||||
getFullDef t n = WordFullDef header defList
|
||||
where
|
||||
header = ((parseDefTags . differentDefTags) t !! (n-1))
|
||||
defList = map (WordDefSentence . renderTags) [parseFullDefTags t]
|
||||
|
||||
parseFullDefTags :: T.Text -> [Tag String]
|
||||
parseFullDefTags = filter (~== "<span class=tlf_cdefinition") . parseTags
|
||||
. T.unpack
|
||||
parseFullDefTags = findRelevantTags . parseTags . T.unpack
|
||||
|
||||
findRelevantTags :: [Tag String] -> [Tag String]
|
||||
findRelevantTags [] = []
|
||||
findRelevantTags (x:xs) = if x ~== "<span class=tlf_cdefinition"
|
||||
|| x ~== "<span class=tlf_cexemple"
|
||||
then maybe (f xs) (\y -> y:(f xs)) (L.find (~== TagText "") xs)
|
||||
else (f xs)
|
||||
where
|
||||
f = findRelevantTags
|
||||
|
Loading…
Reference in New Issue
Block a user