pauza-akademicka/app/pauza.hs
Iwona Christop e358428079 Add pauza.hs
2022-04-17 13:21:43 +02:00

46 lines
1.6 KiB
Haskell

{-# 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 "//p[@class='has-text-align-center']/a[contains(@href, '/20')]"
>>> second (arr $ replace "\r\n " "")
>>> first (arr $ replace "/index.php" "")
>>> first (extractLinksWithText "//h2/a[contains(@href, '.pdf')]")
toShadowItem :: ((String, String), String) -> ShadowItem
toShadowItem ((url, articleTitle), yearlyTitle) =
(defaultShadowItem url title) {
-- originalDate = Just date,
originalDate = Just yearlyTitle,
itype = "periodical",
format = Just "pdf",
finalUrl = url
}
where title = "PAUza Akademicka " ++ yearlyTitle ++ " " ++ (replace "\r\n" "" (replace "\r\n " "" articleTitle))
-- date = getDate url
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://pauza.krakow.pl/"
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
lname="PAUza Akademicka",
abbrev="PAUza",
lLevel=0,
webpage=start}
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)