twilight-library/app/otwarteczasopismauam.hs
2022-04-17 21:15:49 +02:00

46 lines
1.7 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 "//h3[@class='media-heading']/a"
>>> first (arr (++"/issue/archive"))
>>> first (extractLinksWithText "//*[@class='media-heading']/a"
>>> first (extractLinksWithText "//*[@class='media-heading']/a"
>>> first (extractLinks "//div[@class='download']/a")))
toShadowItem :: (((String, String), String), String) -> ShadowItem
toShadowItem (((url, articleTitle), yearlyTitle), journalTitle) =
(defaultShadowItem url title) {
originalDate = Just date,
itype = "periodical",
format = Just "pdf",
finalUrl = url
}
where title = replace "\n" "" (replace "\t" "" (journalTitle ++ " " ++ yearlyTitle ++ " " ++ articleTitle))
date = getDate yearlyTitle
getDate yearlyTitle =
case yearlyTitle =~~ "(19[0-9][0-9]|20[0-9][0-9])" :: Maybe [[String]] of
Just [[_, year]] -> year
otherwise -> error $ "unexpected text: " ++ yearlyTitle
main = do
let start = "https://pressto.amu.edu.pl"
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
lname="Otwarte Czasopisma Naukowe UAM",
abbrev="OtwCzasNaukUAM",
lLevel=0,
webpage=start}
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)