Version 1.0

This commit is contained in:
Dominik 2021-03-30 22:32:28 +02:00
parent d8e664eba4
commit 03ffdeb1f7
2 changed files with 10 additions and 9 deletions

View File

@ -12,21 +12,22 @@ import Text.Regex.Posix
import Text.Printf import Text.Printf
extractRecords = extractLinksWithText "//a[contains(@title,'Aneks')]" -- pary tytuł-adres extractRecords = extractLinksWithText "//a[contains(@title,'Aneks') and contains(text(),'Nr')]"
>>> first (arr $ replace "\r\n " " ") -- czyścimy pierwszy element pary, czyli tytuł z niepotrzebnych białych znaków >>> second (arr $ replace "\r\n " " ")
>>> second (extractLinksWithText "//div/a[contains(@href,'.pdf')]") -- pobieramy stronę z adresu URL i wyciągamy linki z tej strony pasujące do wyrażenia XPathowego >>> first (extractLinksWithText "//div/a[contains(@href,'.pdf')]") -- pobieramy stronę z adresu URL i wyciągamy linki z tej strony pasujące do wyrażenia XPathowego
-- ostatecznie wyjdą trójki? (Tytuł, (link do pdf, blank?)) -- ostatecznie wyjdą trójki? ((Link, tekst: "Wyświetl cały numer"), Numer Magazynu)
-- ... a tutaj te trójki przerabiamy do docelowej struktury ShadowItem -- ... a tutaj te trójki przerabiamy do docelowej struktury ShadowItem
toShadowItem :: (String, (String, String)) -> ShadowItem toShadowItem :: ((String, String), String) -> ShadowItem
toShadowItem (yearlyTitle, (url, blank)) = toShadowItem ((url, blank), yearlyTitle) =
(defaultShadowItem url title) { (defaultShadowItem url title) {
originalDate = Just date, originalDate = Just date,
itype = "periodical", itype = "periodical",
format = Just "pdf", format = Just "pdf",
finalUrl = url finalUrl = url
} }
where title = yearlyTitle ++ " " ++ (replace "\r\n" "" (replace "\r\n " "" blank)) where title = yearlyTitle -- ++ " " ++ blank
date = getDate url date = getDate url
getDate url = getDate url =
@ -42,4 +43,4 @@ main = do
abbrev="ArchAnek", abbrev="ArchAnek",
lLevel=0, lLevel=0,
webpage=start} webpage=start}
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem) extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)

View File

@ -68,7 +68,7 @@ executable aneks
build-depends: base build-depends: base
, hxt , hxt
, hxt-xpath , hxt-xpath
, hxt-curl , hxt-curl
, MissingH , MissingH
, regex-posix , regex-posix
, shadow-library , shadow-library