{-# LANGUAGE Arrows, NoMonomorphismRestriction #-} import ShadowLibrary.Core import Text.XML.HXT.Core import Text.XML.HXT.XPath -- import Text.XML.HXT.Curl import Data.List import Data.List.Utils (replace) import Text.Regex.Posix import Text.Printf extractRecords = extractLinksWithText "//section[@class='widget widget_zzm_gm_archive']//a" -- pary adres-tytuł >>> first (arr $ replace "https" "http") >>> first (extractLinksWithText "//article//h2//a") >>> first (arr $ first (arr $ replace "https" "http")) >>> first (arr $ second (arr $ replace "ń" "n")) >>> first (arr $ second (arr $ replace "ś" "s")) >>> first (arr $ second (arr $ replace "ź" "z")) >>> first (arr $ second (arr $ replace "ł" "l")) >>> first (first (extractLinksWithText "//h1[@class='entry-title']//a[contains(@href,'.pdf')]")) >>> first (arr $ first (arr $ second(arr $ replace "ń" "n"))) >>> first (arr $ first (arr $ second(arr $ replace "ś" "s"))) >>> first (arr $ first (arr $ second(arr $ replace "ź" "z"))) >>> first (arr $ first (arr $ second(arr $ replace "ł" "l"))) -- ... a tutaj te trójki przerabiamy do docelowej struktury ShadowItem toShadowItem :: (((String, String), String), String) -> ShadowItem toShadowItem (((url, articleTitle), articleDatePart), year) = (defaultShadowItem url title) { originalDate = getDate articleDatePart, itype = "periodical", format = Just "pdf", finalUrl = url } where title = articleTitle getDate :: String -> Maybe String getDate url = case url =~~ ("[0-9]* ?[a-zA-Z]+ [0-9]{4}" :: String) of Just year -> Just year otherwise -> Nothing main = do let start = "http://zzm.org.pl/glos-maszynisty/" let shadowLibrary = ShadowLibrary {logoUrl=Nothing, lname="Głos Maszynisty", abbrev="GloMasz", lLevel=0, webpage=start} extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)