twilight-library/app/inspektoratpracy.hs

38 lines
1.2 KiB
Haskell
Raw Normal View History

2022-04-04 20:23:44 +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
extractRecords = extractLinksWithText "//td/a[contains(@href,'.pdf')]"
toShadowItem :: (String, String) -> ShadowItem
2022-05-19 23:28:20 +02:00
toShadowItem (url, title) =
(defaultShadowItem url title) {
2022-04-04 20:23:44 +02:00
originalDate = Just date,
itype = "periodical",
format = Just "pdf",
finalUrl = url
}
2022-05-25 12:48:52 +02:00
where title = "title"
2022-05-19 23:28:20 +02:00
date = getDate $ replace "%20" " " url
getDate :: String -> String
getDate url = date where
date = url Text.Regex.Posix.=~ "(202[0-2]|20[0-1][0-9])" :: String
2022-04-04 20:23:44 +02:00
main = do
let start = "https://www.pip.gov.pl/pl/inspektor-pracy/66546,archiwum-inspektora-pracy-.html"
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
lname="Inspektor Pracy",
abbrev="InspPrac",
lLevel=0,
webpage=start}
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)