46 lines
1.4 KiB
Haskell
46 lines
1.4 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 "//a[contains(@href,'.pdf')]"
|
||
|
|
||
|
toShadowItem :: (String, String) -> ShadowItem
|
||
|
toShadowItem (url, nr) =
|
||
|
(defaultShadowItem url title) {
|
||
|
originalDate = Just date,
|
||
|
itype = "periodical",
|
||
|
format = Just "pdf",
|
||
|
finalUrl = url
|
||
|
}
|
||
|
where title = "Wszechświat " ++ "Rok " ++ getDate url ++ " " ++ getNr nr
|
||
|
date = getDate url
|
||
|
|
||
|
getDate url =
|
||
|
case url =~~ "/pdf_(19[0-9][0-9]|20[0-9][0-9]|18[0-9][0-9]|19[0-9][0-9]_19[0-9][0-9])/" :: Maybe [[String]] of
|
||
|
Just [[_, year]] -> year
|
||
|
otherwise -> error $ "unexpected url: " ++ url
|
||
|
|
||
|
getNr nr =
|
||
|
case nr =~~ "(Nr [0-9][0-9]|Nr [0-9][0-9]-[0-9][0-9])" :: Maybe [[String]] of
|
||
|
Just [[_, nr]] -> nr
|
||
|
otherwise -> error $ "unexpected url: " ++ nr
|
||
|
|
||
|
main = do
|
||
|
let start = "https://www.ptpk.org/archiwum.html"
|
||
|
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
||
|
lname="Czasopismo Wszechświat",
|
||
|
abbrev="Wszechświat",
|
||
|
lLevel=0,
|
||
|
webpage=start}
|
||
|
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|