{-# 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 "//td/a[contains(@href,'.pdf')]" toShadowItem :: (String, String) -> ShadowItem toShadowItem (url, monthlytitle) = (defaultShadowItem url title) { originalDate = Just date, itype = "periodical", format = Just "pdf", finalUrl = url } where title = "IP" ++ date ++ " " ++ (replace "\r" "" (replace "\n" "" (replace "\t" "" monthlytitle))) date = getDate $ replace "%20" " " url getDate :: String -> String getDate url = date where date = url Text.Regex.Posix.=~ "(202[0-2]|20[0-1][0-9])" :: String main = do let start = "https://www.pip.gov.pl/pl/inspektor-pracy/66546,archiwum-inspektora-pracy-.html" let shadowLibrary = ShadowLibrary {logoUrl=Nothing, lname="Inspektor Pracy", abbrev="InspPrac", lLevel=0, webpage=start} extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)