twilight-library/app/naszepopowice.hs

48 lines
1.5 KiB
Haskell
Raw Normal View History

2021-03-16 18:37:17 +01:00
{-# LANGUAGE Arrows, NoMonomorphismRestriction #-}
import ShadowLibrary.Core
import Text.XML.HXT.Core
import Text.XML.HXT.XPath
import Data.List
import Data.List.Utils (replace)
import Text.Regex.Posix
import Text.Printf
extractRecords = extractLinksWithText "//a[contains(@href,'.pdf') and contains(text(),'popowice')]"
2021-03-16 18:37:17 +01:00
toShadowItem :: (String, String) -> ShadowItem
toShadowItem (url, articleTitle) =
2021-03-16 18:37:17 +01:00
(defaultShadowItem url title) {
originalDate = Just date,
itype = "periodical",
2021-04-10 11:05:32 +02:00
format = Just "pdf"
2021-03-16 18:37:17 +01:00
}
where title = "Nasze Popowice " ++ getNr url
2021-03-16 18:37:17 +01:00
date = getDate url
replaceSeparatorWithSpace = map (\c -> if c=='_' then ' '; else if c=='-' then ' '; else c)
2021-04-10 11:05:32 +02:00
replaceUnderscoreWithDash = 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
2021-03-16 18:37:17 +01:00
getDate url =
case url =~~ "20[0-9][0-9]_[0-1][0-9]" :: Maybe String of
2021-04-10 11:05:32 +02:00
Just date -> replaceUnderscoreWithDash date
2021-03-16 18:37:17 +01:00
otherwise -> error $ "unexpected url: " ++ url
main = do
let start = "https://smpopowice.pl/index.php/numery-archiwalne"
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
lname="Nasze Popowice",
abbrev="NaszPop",
2021-03-16 18:37:17 +01:00
lLevel=0,
webpage=start}
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)