forked from filipg/twilight-library
50 lines
1.6 KiB
Haskell
50 lines
1.6 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') and contains(text(),'czasopisma_francja')]"
|
|
|
|
toShadowItem :: (String, String) -> ShadowItem
|
|
toShadowItem (url, articleTitle) =
|
|
(defaultShadowItem url title) {
|
|
originalDate = Just date,
|
|
itype = "periodical",
|
|
format = Just "pdf",
|
|
finalUrl = url
|
|
}
|
|
where title = "czasopisma_francja " ++ getNr url
|
|
date = getDate url
|
|
|
|
replaceSeparatorWithSpace = map (\c -> if c=='_' then ' '; else if c=='-' then ' '; else c)
|
|
replaceSeparatorWithDot = map (\c -> if c=='_' then '.'; else c)
|
|
|
|
getNr url =
|
|
case url =~~ "nr[-_][0-9][0-9]" :: Maybe String of
|
|
Just nr -> replaceSeparatorWithSpace nr
|
|
otherwise -> error $ "unexpected url: " ++ url
|
|
|
|
getDate url =
|
|
case url =~~ "20[0-9][0-9]_[0-1][0-9]" :: Maybe String of
|
|
Just date -> replaceSeparatorWithDot date
|
|
otherwise -> error $ "unexpected url: " ++ url
|
|
|
|
|
|
main = do
|
|
let start = "http://www.almanachmuszyny.pl/"
|
|
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
|
lname="czasopisma_francja",
|
|
abbrev="CzasFr",
|
|
lLevel=0,
|
|
webpage=start}
|
|
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|