twilight-library/app/otwarteczasopismauam.hs

51 lines
2.0 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.TDFA
-- import Text.Regex.TDFA.Text ()
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"
>>> extractLinks "//a[@class='download']")))
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
getDate :: String -> String
getDate yearlyTitle = date where
date = yearlyTitle Text.Regex.TDFA.=~ "(19[0-9][0-9]|20[0-9][0-9])" :: String
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)