twilight-library/app/instytutTechnikiGorniczej.hs

50 lines
1.8 KiB
Haskell
Raw Normal View History

2022-04-07 20:57:15 +02:00
{-# 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
2022-05-05 19:07:52 +02:00
2022-04-07 20:57:15 +02:00
extractRecords = extractLinksWithText "//li/a[contains(@href,'/lata')]"
2022-05-05 19:07:52 +02:00
>>> first (extractLinksWithText "//li/a[contains(@href,'start=')]"
>>> first (extractLinksWithText "//a[contains(@href, '/archiwum/images/19') or contains(@href, '/Trybuna')]"))
2022-04-07 20:57:15 +02:00
2022-05-05 19:07:52 +02:00
toShadowItem :: (((String, String), String), String) -> ShadowItem
toShadowItem (((url, articleTitle), _), yearlyTitle) =
2022-04-07 20:57:15 +02:00
(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 =
2022-05-05 19:07:52 +02:00
case url =~~ "(19[0-9][0-9]|20[0-9][0-9]).*\\..{3}" :: Maybe [[String]] of
2022-04-07 20:57:15 +02:00
Just [[_, year]] -> year
otherwise -> error $ "unexpected url: " ++ url
2022-05-05 19:07:52 +02:00
2022-04-07 20:57:15 +02:00
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)