{-# LANGUAGE Arrows, NoMonomorphismRestriction #-} import ShadowLibrary.Core import Text.XML.HXT.Core import Text.XML.HXT.XPath import Data.List import Data.List.Utils (replace) import Text.Regex.Posix import Text.Printf extractRecords = extractLinksWithText "//a[contains(@href,'.pdf') and contains(text(),'popowice')]" toShadowItem :: (String, String) -> ShadowItem toShadowItem (url, articleTitle) = (defaultShadowItem url title) { originalDate = Just date, itype = "periodical", format = Just "pdf" } where title = "Nasze Popowice " ++ getNr url date = getDate url replaceSeparatorWithSpace = map (\c -> if c=='_' then ' '; else if c=='-' then ' '; else c) replaceUnderscoreWithDash = map (\c -> if c=='_' then '-'; else c) getNr url = case url =~~ "nr[-_][0-9][0-9]" :: Maybe String of Just nr -> replaceSeparatorWithSpace nr otherwise -> error $ "unexpected url: " ++ url getDate url = case url =~~ "20[0-9][0-9]_[0-1][0-9]" :: Maybe String of Just date -> replaceUnderscoreWithDash date otherwise -> error $ "unexpected url: " ++ url main = do let start = "https://smpopowice.pl/index.php/numery-archiwalne" let shadowLibrary = ShadowLibrary {logoUrl=Nothing, lname="Nasze Popowice", abbrev="NaszPop", lLevel=0, webpage=start} extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)