2021-04-05 18:48:35 +02:00
|
|
|
|
|
|
|
{-# LANGUAGE Arrows, NoMonomorphismRestriction #-}
|
2021-04-06 23:25:55 +02:00
|
|
|
|
2021-04-05 18:48:35 +02:00
|
|
|
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
|
|
|
|
|
2021-04-07 01:03:47 +02:00
|
|
|
extractNestedLinksWithText xpathCondition = (downloadDocument &&& this)
|
2021-04-06 23:25:55 +02:00
|
|
|
>>> first (getXPathTrees xpathCondition
|
|
|
|
>>> ((getXPathTrees "//a" >>> getAttrValue "href")
|
|
|
|
&&& (listA (deep isText >>> getText)
|
|
|
|
>>> arr (intercalate " "))))
|
|
|
|
>>> arr rotateSecTh
|
|
|
|
>>> first expandURIFixed
|
2021-04-05 18:48:35 +02:00
|
|
|
|
2021-04-06 23:25:55 +02:00
|
|
|
extractRecords = extractLinksWithText "//div[@class='entry-content']/p/a[contains(@href, 'id')]"
|
2021-04-07 01:03:47 +02:00
|
|
|
>>> first (arr $ replace "http:" "https:")
|
2021-04-06 23:25:55 +02:00
|
|
|
>>> first (extractNestedLinksWithText "//div[@class='entry-content']/p[strong[a]] | //div[@class='entry-content']/p[a]")
|
2021-04-05 18:48:35 +02:00
|
|
|
|
|
|
|
toShadowItem :: ((String, String), String) -> ShadowItem
|
2021-04-06 23:25:55 +02:00
|
|
|
toShadowItem ((url, articleTitle), magazineTitle) =
|
2021-04-05 18:48:35 +02:00
|
|
|
(defaultShadowItem url title) {
|
|
|
|
originalDate = Just date,
|
|
|
|
itype = "periodical",
|
|
|
|
format = Just "pdf",
|
|
|
|
finalUrl = url
|
|
|
|
}
|
2021-04-06 23:25:55 +02:00
|
|
|
where title = magazineTitle ++ " - " ++ (replace " \8211 pdf" "" articleTitle)
|
|
|
|
date = getYear url
|
2021-04-05 18:48:35 +02:00
|
|
|
|
2021-04-06 23:25:55 +02:00
|
|
|
getYear :: String -> String
|
|
|
|
getYear url =
|
2021-04-07 01:03:47 +02:00
|
|
|
case url =~~ "/(rocznik[0-9][0-9])/" :: Maybe [[String]] of
|
|
|
|
Just [[_, raw_year]] -> "19" ++ (replace "rocznik" "" raw_year)
|
2021-04-06 23:25:55 +02:00
|
|
|
otherwise -> case url =~~ "/(19[0-9][0-9]|20[0-9][0-9])/" :: Maybe [[String]] of
|
2021-04-07 01:03:47 +02:00
|
|
|
Just [[_, year]] -> year
|
2021-04-06 23:25:55 +02:00
|
|
|
otherwise -> ""
|
2021-04-05 18:48:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
main = do
|
|
|
|
let baseUrl = "https://www.ptd.pl/?page_id=7"
|
|
|
|
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
|
|
|
lname="Polskie Towarzystwo Dendrologiczne",
|
|
|
|
abbrev="ptd",
|
|
|
|
lLevel=0,
|
|
|
|
webpage=baseUrl}
|
2021-04-06 23:25:55 +02:00
|
|
|
extractItemsStartingFromUrl shadowLibrary baseUrl (extractRecords >>> arr toShadowItem)
|