forked from filipg/twilight-library
49 lines
1.7 KiB
Haskell
49 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 "//li/a[contains(@href,'/lata')]"
|
||
|
>>> second (arr $ replace "\r\n " " ")
|
||
|
>>> first (extractLinksWithText "//p/a[contains(@href, '/archiwum/images/gazety')]")
|
||
|
|
||
|
toShadowItem :: ((String, String), String) -> ShadowItem
|
||
|
toShadowItem ((url, articleTitle), yearlyTitle) =
|
||
|
(defaultShadowItem url title) {
|
||
|
originalDate = Just date,
|
||
|
itype = "periodical",
|
||
|
format = Just form,
|
||
|
-- format = Just "pdf",
|
||
|
finalUrl = url
|
||
|
}
|
||
|
where title = "Instytut Techniki Gorniczej " ++ yearlyTitle ++ " " ++ (replace "\r\n" "" (replace "\r\n " "" articleTitle))
|
||
|
date = getDate $ replace "%20" "" url
|
||
|
form = unwords $ map stringToLower [getFormat url]
|
||
|
|
||
|
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
|
||
|
|
||
|
getFormat url =
|
||
|
case url =~~ "([a-zA-Z]+$)" :: Maybe [[String]] of
|
||
|
Just [[_, format]] -> format
|
||
|
otherwise -> error $ "unexpected url: " ++ url
|
||
|
|
||
|
main = do
|
||
|
let start = "http://komag.gliwice.pl/archiwum/historia-komag/"
|
||
|
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
||
|
lname="Instytut Techniki Gorniczej",
|
||
|
abbrev="Komag",
|
||
|
lLevel=0,
|
||
|
webpage=start}
|
||
|
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|