{-# 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[@id='section-content']//h2/a" -- pary adres-tytuł >>> second (arr $ replace "\r\n " " ") -- czyścimy drugi element pary, czyli tytuł z niepotrzebnych białych znaków -- >>> first (arr ((++"tr") . init)) -- modyfikujemy pierwszy element pary, czyli adres URL >>> first (extractLinksWithText "//div[@class='attachment']/a[contains(@href, '.pdf')]") -- pobieramy stronę z adresu URL i wyciągamy linki z tej strony pasujące do wyrażenia XPathowego -- ostatecznie wyjdą trójki ((adres URL, tytuł artykułu), tytuł rocznika) -- ... a tutaj te trójki przerabiamy do docelowej struktury ShadowItem toShadowItem :: ((String, String), String) -> ShadowItem toShadowItem ((url, articleTitle), yearlyTitle) = (defaultShadowItem url title) { originalDate = Just date, itype = "periodical", format = Just "pdf", finalUrl = url } where title = "Teksty Drugie " ++ yearlyTitle ++ " " ++ (replace "\r\n" "" (replace "\r\n " "" articleTitle)) date = getDate url getDate url = case url =~~ "/([1-2][0-9][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://tekstydrugie.pl/pl/numery-archiwalne/" let shadowLibrary = ShadowLibrary {logoUrl=Nothing, lname="Teksty Drugie", abbrev="TekDru", lLevel=0, webpage=start} let start1 = "http://tekstydrugie.pl/pl/numery-archiwalne/1990/" let start2 = "http://tekstydrugie.pl/pl/numery-archiwalne/1991/" let start3 = "http://tekstydrugie.pl/pl/numery-archiwalne/1992/" let start4 = "http://tekstydrugie.pl/pl/numery-archiwalne/1993/" let start5 = "http://tekstydrugie.pl/pl/numery-archiwalne/1994/" let start6 = "http://tekstydrugie.pl/pl/numery-archiwalne/1995/" let start7 = "http://tekstydrugie.pl/pl/numery-archiwalne/1996/" let start8 = "http://tekstydrugie.pl/pl/numery-archiwalne/1997/" let start9 = "http://tekstydrugie.pl/pl/numery-archiwalne/1998/" let start10 = "http://tekstydrugie.pl/pl/numery-archiwalne/1999/" let start11 = "http://tekstydrugie.pl/pl/numery-archiwalne/2000/" let start12 = "http://tekstydrugie.pl/pl/numery-archiwalne/2001/" let start13 = "http://tekstydrugie.pl/pl/numery-archiwalne/2002/" let start14 = "http://tekstydrugie.pl/pl/numery-archiwalne/2003/" let start15 = "http://tekstydrugie.pl/pl/numery-archiwalne/2004/" let start16 = "http://tekstydrugie.pl/pl/numery-archiwalne/2005/" let start17 = "http://tekstydrugie.pl/pl/numery-archiwalne/2006/" let start18 = "http://tekstydrugie.pl/pl/numery-archiwalne/2007/" let start19 = "http://tekstydrugie.pl/pl/numery-archiwalne/2008/" let start20 = "http://tekstydrugie.pl/pl/numery-archiwalne/2009/" let start21 = "http://tekstydrugie.pl/pl/numery-archiwalne/2010/" let start22 = "http://tekstydrugie.pl/pl/numery-archiwalne/2011/" let start23 = "http://tekstydrugie.pl/pl/numery-archiwalne/2012/" let start24 = "http://tekstydrugie.pl/pl/numery-archiwalne/2013/" let start25 = "http://tekstydrugie.pl/pl/numery-archiwalne/2014/" let start26 = "http://tekstydrugie.pl/pl/numery-archiwalne/2015/" let start27 = "http://tekstydrugie.pl/pl/numery-archiwalne/2016/" let start28 = "http://tekstydrugie.pl/pl/numery-archiwalne/2017/" let start29 = "http://tekstydrugie.pl/pl/numery-archiwalne/2018/" let start30 = "http://tekstydrugie.pl/pl/numery-archiwalne/2019/" let start31 = "http://tekstydrugie.pl/pl/numery-archiwalne/2020/" let start32 = "http://tekstydrugie.pl/pl/numery-archiwalne/2021/" extractItemsStartingFromUrl shadowLibrary start1 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start2 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start3 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start4 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start5 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start6 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start7 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start8 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start9 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start10 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start11 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start12 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start13 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start14 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start15 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start16 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start17 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start18 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start19 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start20 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start21 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start22 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start23 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start24 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start25 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start26 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start27 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start28 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start29 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start30 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start31 (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start32 (extractRecords >>> arr toShadowItem)