forked from filipg/twilight-library
Zwracanie Nothing zamiast pustego stringa, dodanie funkcji mapującej
This commit is contained in:
parent
5272c99c3a
commit
8d86f78924
20
app/ptd.hs
20
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"
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user