forked from filipg/twilight-library
47 lines
1.7 KiB
Haskell
47 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
|
|
|
|
extractAllPDFs = extractLinksWithText "/html/body/table[4]/tbody/tr[7]/td[2]/a"
|
|
|
|
extractRecords = extractLinksWithText "//table[3]//a"
|
|
>>> first (extractLinksWithText "//table[3]//a"
|
|
>>> first (extractLinksWithText "//table[4]//a"
|
|
>>> first (extractAllPDFs
|
|
>>> first(arr $ (drop 23 ) . init . init . init))))
|
|
|
|
toShadowItem :: ((((String, String), String), String), String) -> ShadowItem
|
|
toShadowItem ((((url, typeName), articleTitle), _), category) =
|
|
(defaultShadowItem url title) {
|
|
originalDate = Just date,
|
|
itype = "periodical",
|
|
format = Just "pdf",
|
|
finalUrl = url
|
|
}
|
|
where title = "Biblioteka Sejmowa " ++ category ++ " " ++ typeName ++ " " ++ articleTitle
|
|
date = getDate articleTitle
|
|
|
|
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 = "https://bs.sejm.gov.pl/F/?con_lng=POL&func=file&file_name=find-nowe&local_base=ars01"
|
|
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
|
lname="Biblioteka Sejmowa",
|
|
abbrev="BiblSejm",
|
|
lLevel=0,
|
|
webpage=start}
|
|
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|