twilight-library/app/teatrLalek.hs

40 lines
1.1 KiB
Haskell
Raw Normal View History

2022-04-10 23:51:13 +02:00
{-# 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 = extractLinks "//a[contains(@href, '.pdf')]"
toShadowItem :: String -> ShadowItem
toShadowItem url =
2022-06-15 22:27:32 +02:00
(defaultShadowItem url title) {
2022-04-10 23:51:13 +02:00
originalDate = Just date,
itype = "periodical",
format = Just "pdf",
finalUrl = url
}
where
date = last $ getAllTextMatches $ url =~ "(19[0-9][0-9]|20[0-9][0-9])" :: String
2022-06-15 22:27:32 +02:00
titleToProcess = last $ getAllTextMatches $ url =~ "/[a-zA-Z ]+[-_]" :: String
title = titleToProcess =~ "[a-zA-Z ]+" :: String
2022-04-10 23:51:13 +02:00
main = do
let start = "http://polunima.pl/teatr-lalek/"
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
lname="Teatr Lalek",
abbrev="Teatr",
lLevel=0,
webpage=start}
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)