50 lines
1.8 KiB
Haskell
50 lines
1.8 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')]"
|
|
>>> first (extractLinksWithText "//li/a[contains(@href,'start=')]"
|
|
>>> first (extractLinksWithText "//a[contains(@href, '/archiwum/images/19') or contains(@href, '/Trybuna')]"))
|
|
|
|
|
|
toShadowItem :: (((String, String), String), String) -> ShadowItem
|
|
toShadowItem (((url, articleTitle), _), yearlyTitle) =
|
|
(defaultShadowItem url title) {
|
|
originalDate = Just date,
|
|
itype = "periodical",
|
|
format = Just form,
|
|
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]).*\\..{3}" :: 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)
|