Compare commits

...

6 Commits

5 changed files with 105 additions and 8 deletions

View File

@ -33,7 +33,7 @@ import Data.Tree.NTree.TypeDefs
import Data.Maybe
import Control.Monad.Trans
import Text.XML.HXT.XPath
-- import Text.XML.HXT.Curl
import Text.XML.HXT.Curl
import Text.XML.HXT.HTTP
import Text.Regex.TDFA
@ -64,8 +64,8 @@ downloadDocument = readFromDocument [withParseHTML yes,
withEncodingErrors no,
withPreserveComment yes,
withStrictInput yes,
withHTTP []
-- withCurl [("curl--user-agent","AMU Digital Libraries Indexing Agent")]
-- withHTTP []
withCurl [("curl--user-agent","AMU Digital Libraries Indexing Agent")]
]
downloadDocumentWithEncoding enc = readFromDocument [withParseHTML yes,
@ -73,13 +73,13 @@ downloadDocumentWithEncoding enc = readFromDocument [withParseHTML yes,
withEncodingErrors no,
withPreserveComment yes,
withInputEncoding enc,
withHTTP []]
-- withCurl []]
-- withHTTP []]
withCurl []]
downloadXmlDocument = readFromDocument [withWarnings no,
withEncodingErrors no,
withHTTP []]
-- withCurl [] ]
-- withHTTP []]
withCurl [] ]
data ShadowLibrary = ShadowLibrary { logoUrl :: Maybe String,

View File

@ -4,7 +4,7 @@ import ShadowLibrary.Core
import Text.XML.HXT.Core
import Text.XML.HXT.XPath
-- import Text.XML.HXT.Curl
--import Text.XML.HXT.Curl
import Data.List
import Data.List.Utils (replace)

63
app/ptd.hs Normal file
View File

@ -0,0 +1,63 @@
{-# LANGUAGE Arrows, NoMonomorphismRestriction #-}
import ShadowLibrary.Core
import Text.XML.HXT.Core
import Text.XML.HXT.XPath
import Data.List
import Data.List.Utils (replace)
import Text.Regex.Posix
import Text.Printf
extractNestedLinksWithText xpathCondition = (downloadDocument &&& this)
>>> first (getXPathTrees xpathCondition
>>> ((getXPathTrees "//a" >>> getAttrValue "href")
&&& (listA (deep isText >>> getText)
>>> arr (intercalate " "))))
>>> arr rotateSecTh
>>> first expandURIFixed
extractRecords = extractLinksWithText "//div[@class='entry-content']/p/a[contains(@href, 'id')]"
>>> first (arr $ replace "http:" "https:")
>>> first (extractNestedLinksWithText "//div[@class='entry-content']/p[strong[a]] | //div[@class='entry-content']/p[a]")
toShadowItem :: ((String, String), String) -> ShadowItem
toShadowItem ((url, articleTitle), magazineTitle) =
(defaultShadowItem url title) {
originalDate = date,
itype = "periodical",
format = Just "pdf",
finalUrl = url
}
where title = magazineTitle ++ " - " ++ (replace " \8211 pdf" "" articleTitle)
date = getYear url
getYear :: String -> Maybe String
getYear url =
case url =~~ "/(rocznik[0-9][0-9])/" :: Maybe [[String]] of
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]] -> (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"
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
lname="Polskie Towarzystwo Dendrologiczne",
abbrev="ptd",
lLevel=0,
webpage=baseUrl}
extractItemsStartingFromUrl shadowLibrary baseUrl (extractRecords >>> arr toShadowItem)

19
readme.md Normal file
View File

@ -0,0 +1,19 @@
# PTD - Polskie Towarzystwo Dendrologiczne
## Wywołanie programu
```bash
stack build
stack exec ptd
```
## Przykładowa krotka wynikowa:
Tytuł w postaci Wydawnictwo - Tytuł
```
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 zwrócone zostanie ```Nothing```
## Dodatkowe paczki zainstalowane na potrzebę uruchomienia programu:
```bash
apt-get install libcurl4-gnutls-dev
```

View File

@ -20,6 +20,7 @@ library
, HTTP
, hxt
, hxt-http
, hxt-curl
, hxt-xpath
, MissingH
, monad-logger
@ -54,12 +55,26 @@ executable almanachmuszyny
build-depends: base
, hxt
, hxt-xpath
, hxt-curl
, MissingH
, regex-posix
, shadow-library
default-language: Haskell2010
executable ptd
hs-source-dirs: app
main-is: ptd.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, hxt
, hxt-xpath
, hxt-curl
, MissingH
, regex-posix
, shadow-library
default-language: Haskell2010
source-repository head
type: git
location: https://github.com/name/project