forked from filipg/twilight-library
46 lines
1.7 KiB
Haskell
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 "//a[contains(@href,'.pdf')]"
|
||
|
>>> second (arr $ replace "\r\n " " ")
|
||
|
|
||
|
toShadowItem :: ((String, String)) -> ShadowItem
|
||
|
toShadowItem ((url, periodicalTitle)) =
|
||
|
(defaultShadowItem url title) {
|
||
|
originalDate = Just date,
|
||
|
itype = "periodical",
|
||
|
format = Just "pdf",
|
||
|
finalUrl = url
|
||
|
}
|
||
|
where title = "Sulimczyk - pismo harcerskie" ++ " " ++ (replace "\r\n" "" (replace "\r\n " "" periodicalTitle))
|
||
|
date = getDate $ show $ periodicalTitle
|
||
|
|
||
|
getDate title =
|
||
|
case title =~~ "(([0-9][0-9]{0,1}) ([I|V|X]{1,3}) (19[0-9][0-9]|20[0-9][0-9]))" :: Maybe String of
|
||
|
Just date -> date
|
||
|
otherwise ->
|
||
|
case title =~~ "(0[1-9]|[12][0-9]|3[01]).(0[1-9]|1[0-2]).((1[789]|20)[0-9][0-9])" :: Maybe String of
|
||
|
Just date -> date
|
||
|
otherwise ->
|
||
|
case title =~~ "(19[0-9][0-9]|20[0-9][0-9])" :: Maybe String of
|
||
|
Just year -> year
|
||
|
otherwise -> error $ "unexpected title: " ++ title
|
||
|
|
||
|
main = do
|
||
|
let start = "http://www.16wdh.pl/s28,Sulimczyk"
|
||
|
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
||
|
lname="Sulimczyk - pismo harcerskie",
|
||
|
abbrev="SulPis",
|
||
|
lLevel=0,
|
||
|
webpage=start}
|
||
|
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|