twilight-library/app/jujitsu.hs

49 lines
1.5 KiB
Haskell
Raw Permalink Normal View History

2022-03-16 11:33:07 +01: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-03-16 16:31:16 +01:00
extractRecords = extractLinksWithText "//a[font]" -- pary adres-tytuł
2022-03-16 11:33:07 +01:00
-- ... a tutaj te trójki przerabiamy do docelowej struktury ShadowItem
2022-03-16 16:31:16 +01:00
toShadowItem :: (String, String) -> ShadowItem
toShadowItem (url, title) =
2022-03-16 11:33:07 +01:00
(defaultShadowItem url title) {
2022-03-16 16:31:16 +01:00
originalDate = date,
2022-03-16 11:33:07 +01:00
itype = "periodical",
format = Just "pdf",
finalUrl = url
}
2022-03-16 16:31:16 +01:00
where date = extractYear title
extractMonth :: String -> Maybe String
extractMonth n =
case n =~~ ("/(styczeń|luty|marzec|kwiecien|maj|czerwiec|lipiec|sierpień|wrzesień|październik|listopad|grudzień)/" :: String) of
Just month -> Just month
otherwise -> Nothing
2022-03-16 11:33:07 +01:00
getDate url =
case url =~~ "/(19[0-9][0-9]|20[0-9][0-9])/" :: Maybe [[String]] of
Just [[_, year]] -> year
otherwise -> error $ "unexpected url: " ++ url
main = do
let start = "http://kobudo.pl/artykuly_jujutsu.html"
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
lname="Jujitsu",
abbrev="Juji",
lLevel=0,
webpage="http://kobudo.pl"}
2022-03-16 16:31:16 +01:00
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)