{-# 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 "//a[font]" -- pary adres-tytuł -- ... a tutaj te trójki przerabiamy do docelowej struktury ShadowItem toShadowItem :: (String, String) -> ShadowItem toShadowItem (url, title) = (defaultShadowItem url title) { originalDate = date, itype = "periodical", format = Just "pdf", finalUrl = url } where date = extractYear title extractMonth :: String -> Maybe String extractMonth n = case n =~~ ("/(styczeń|luty|marzec|kwiecien|maj|czerwiec|lipiec|sierpień|wrzesień|październik|listopad|grudzień)/" :: String) of Just month -> Just month otherwise -> Nothing getDate url = case url =~~ "/(19[0-9][0-9]|20[0-9][0-9])/" :: Maybe [[String]] of Just [[_, year]] -> year otherwise -> error $ "unexpected url: " ++ url main = do let start = "http://kobudo.pl/artykuly_jujutsu.html" let shadowLibrary = ShadowLibrary {logoUrl=Nothing, lname="Jujitsu", abbrev="Juji", lLevel=0, webpage="http://kobudo.pl"} extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)