twilight-library/app/inspektoratpracy.hs

38 lines
1.3 KiB
Haskell
Raw Permalink 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-25 13:06:30 +02:00
toShadowItem (url, monthlytitle) =
2022-05-19 23:28:20 +02:00
(defaultShadowItem url title) {
2022-04-04 20:23:44 +02:00
originalDate = Just date,
itype = "periodical",
format = Just "pdf",
finalUrl = url
}
2022-05-25 21:02:59 +02:00
where title = "IP" ++ date ++ " " ++ (replace "\r" "" (replace "\n" "" (replace "\t" "" monthlytitle)))
2022-05-25 13:06:30 +02:00
date = getDate $ replace "%20" " " url
2022-05-19 23:28:20 +02:00
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)