From 8d86f789244294cca8a3be7ed2065c49efb2e83c Mon Sep 17 00:00:00 2001 From: Anna Nowak Date: Wed, 7 Apr 2021 15:07:27 +0200 Subject: [PATCH] =?UTF-8?q?Zwracanie=20Nothing=20zamiast=20pustego=20strin?= =?UTF-8?q?ga,=20dodanie=20funkcji=20mapuj=C4=85cej?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ptd.hs | 20 +++++++++++++++----- readme.md | 5 +++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/ptd.hs b/app/ptd.hs index 4d6a021..2d23b96 100644 --- a/app/ptd.hs +++ b/app/ptd.hs @@ -26,7 +26,7 @@ extractRecords = extractLinksWithText "//div[@class='entry-content']/p/a[contain toShadowItem :: ((String, String), String) -> ShadowItem toShadowItem ((url, articleTitle), magazineTitle) = (defaultShadowItem url title) { - originalDate = Just date, + originalDate = date, itype = "periodical", format = Just "pdf", finalUrl = url @@ -34,14 +34,24 @@ toShadowItem ((url, articleTitle), magazineTitle) = where title = magazineTitle ++ " - " ++ (replace " \8211 pdf" "" articleTitle) date = getYear url -getYear :: String -> String +getYear :: String -> Maybe String getYear url = case url =~~ "/(rocznik[0-9][0-9])/" :: Maybe [[String]] of - Just [[_, raw_year]] -> "19" ++ (replace "rocznik" "" raw_year) + Just [[_, raw_year]] -> Just (catalogueMapper (replace "rocznik" "" raw_year)) otherwise -> case url =~~ "/(19[0-9][0-9]|20[0-9][0-9])/" :: Maybe [[String]] of - Just [[_, year]] -> year - otherwise -> "" + Just [[_, year]] -> (Just year) + otherwise -> Nothing +-- Rozwiązanie także zadziała +-- catalogueMapper :: String -> String +-- catalogueMapper number = show((read number :: Integer) + 1952) + +catalogueMapper :: String -> String +catalogueMapper number + | number == "67" = "2019" + | number == "66" = "2018" + | number == "65" = "2017" + | number == "64" = "2016" main = do let baseUrl = "https://www.ptd.pl/?page_id=7" diff --git a/readme.md b/readme.md index cf08a0c..e630876 100644 --- a/readme.md +++ b/readme.md @@ -9,9 +9,10 @@ stack exec ptd ## Przykładowa krotka wynikowa: Tytuł w postaci Wydawnictwo - Tytuł ``` -ShadowItem {url = Just "http://www.ptd.pl/ptd/wp-content/download/2014/7-Plyty.pdf", title = "Pe\322ne teksty Rocznik\243w PTD, pocz\261wszy od zeszytu 57; \nwersja online \8211 ISSN 2300-8326 - PIOTR DASZKIEWICZ \nP\322yty miedziane i miedzioryty Pierre Richer de Bellevala (1555-1632) w Rzeczpospolitej Obojga Narod\243w \8211 z punktu widzenia historii botaniki\8211 \nPierre Richer de Belleval\8217s (1555-1632) copperplates in the Polish-Lithuanian Commonwealth from the point of view of the history of botany ", itype = "periodical", originalDate = Just "2014", creator = Nothing, format = Just "pdf", lang = Just "pol", finalUrl = "http://www.ptd.pl/ptd/wp-content/download/2014/7-Plyty.pdf", description = Nothing} +ShadowItem {url = Just "http://www.ptd.pl/ptd/wp-content/download/wydawnictwaPTD/rocznik67/12_R_67_Digitalizacja.pdf", title = "Pe\322ne teksty Rocznik\243w PTD, pocz\261wszy od zeszytu 57; \nwersja online \8211 ISSN 2300-8326 - DOMINIK TOMASZEWSKI \nDigitalizacja zbior\243w zielnikowych \8211 krok w dobr\261 stron\281\8211 \nDigitisation of herbarium collections \8211 a step in the right direction \8211 \160pdf", itype = "periodical", originalDate = Just "2019", creator = Nothing, format = Just "pdf", lang = Just "pol", finalUrl = "http://www.ptd.pl/ptd/wp-content/download/wydawnictwaPTD/rocznik67/12_R_67_Digitalizacja.pdf", description = Nothing} ``` -W przypadku braku roku znajduje się pusty string +W przypadku braku roku zwrócone zostanie ```Nothing``` + ## Dodatkowe paczki zainstalowane na potrzebę uruchomienia programu: ```bash apt-get install libcurl4-gnutls-dev