Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
dc83563238 | |||
|
0a241f4892 | ||
268eeaa44c | |||
cb52905362 | |||
e9a2d312cf | |||
|
d6f50c859b | ||
|
76146d4e09 | ||
|
0231c45a80 | ||
|
d5351842eb |
7
README.md
Normal file
7
README.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Build and run project
|
||||||
|
|
||||||
|
`stack install`
|
||||||
|
|
||||||
|
`stack build`
|
||||||
|
|
||||||
|
`stack exec czasopisma`
|
@ -33,7 +33,7 @@ import Data.Tree.NTree.TypeDefs
|
|||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Control.Monad.Trans
|
import Control.Monad.Trans
|
||||||
import Text.XML.HXT.XPath
|
import Text.XML.HXT.XPath
|
||||||
-- import Text.XML.HXT.Curl
|
import Text.XML.HXT.Curl
|
||||||
import Text.XML.HXT.HTTP
|
import Text.XML.HXT.HTTP
|
||||||
|
|
||||||
import Text.Regex.TDFA
|
import Text.Regex.TDFA
|
||||||
@ -64,8 +64,7 @@ downloadDocument = readFromDocument [withParseHTML yes,
|
|||||||
withEncodingErrors no,
|
withEncodingErrors no,
|
||||||
withPreserveComment yes,
|
withPreserveComment yes,
|
||||||
withStrictInput yes,
|
withStrictInput yes,
|
||||||
withHTTP []
|
withCurl [("curl--user-agent","AMU Digital Libraries Indexing Agent")]
|
||||||
-- withCurl [("curl--user-agent","AMU Digital Libraries Indexing Agent")]
|
|
||||||
]
|
]
|
||||||
|
|
||||||
downloadDocumentWithEncoding enc = readFromDocument [withParseHTML yes,
|
downloadDocumentWithEncoding enc = readFromDocument [withParseHTML yes,
|
||||||
@ -73,13 +72,12 @@ downloadDocumentWithEncoding enc = readFromDocument [withParseHTML yes,
|
|||||||
withEncodingErrors no,
|
withEncodingErrors no,
|
||||||
withPreserveComment yes,
|
withPreserveComment yes,
|
||||||
withInputEncoding enc,
|
withInputEncoding enc,
|
||||||
withHTTP []]
|
withCurl []]
|
||||||
-- withCurl []]
|
|
||||||
|
|
||||||
downloadXmlDocument = readFromDocument [withWarnings no,
|
downloadXmlDocument = readFromDocument [withWarnings no,
|
||||||
withEncodingErrors no,
|
withEncodingErrors no,
|
||||||
withHTTP []]
|
-- withHTTP []]
|
||||||
-- withCurl [] ]
|
withCurl [] ]
|
||||||
|
|
||||||
|
|
||||||
data ShadowLibrary = ShadowLibrary { logoUrl :: Maybe String,
|
data ShadowLibrary = ShadowLibrary { logoUrl :: Maybe String,
|
||||||
|
54
app/czasopisma.hs
Normal file
54
app/czasopisma.hs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
{-# 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
|
||||||
|
|
||||||
|
|
||||||
|
extractRecords = extractLinksWithText "" -- pary adres-tytuł
|
||||||
|
>>> first (extractLinksWithText "//a[@target='_blank'][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 ((adres URL, tytuł artykułu), tytuł rocznika)
|
||||||
|
|
||||||
|
|
||||||
|
toShadowItem :: ((String, String), String) -> ShadowItem
|
||||||
|
toShadowItem ((url, articleTitle), yearlyTitle) =
|
||||||
|
(defaultShadowItem url title) {
|
||||||
|
originalDate = Just date,
|
||||||
|
itype = "periodical",
|
||||||
|
format = Just "pdf",
|
||||||
|
finalUrl = url
|
||||||
|
}
|
||||||
|
where homeTitle = getTitle url
|
||||||
|
title = replace "_" " " homeTitle ++ "ROK " ++ date ++ " " ++ articleTitle
|
||||||
|
date = getDate url
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
getTitle url =
|
||||||
|
case url =~~ "/([A-Za-z]+_|[A-Za-z]+_[A-Za-z]+_|[A-Za-z]+_[A-Za-z]+_[A-Za-z]+_|[A-Za-z]+_[A-Za-z]+_[A-Za-z]+_[A-Za-z]+_|[A-Za-z]+_[A-Za-z]+_[A-Za-z]+_[A-Za-z]+_[A-Za-z]+_)" :: Maybe [[String]] of
|
||||||
|
Just [[_, title]] -> title
|
||||||
|
otherwise -> error $ "unexpected url2: " ++ url
|
||||||
|
|
||||||
|
|
||||||
|
main = do
|
||||||
|
let start = "https://www.czasopisma.centralnabibliotekapttk.pl"
|
||||||
|
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
||||||
|
lname="Czasopisma PTTK",
|
||||||
|
abbrev="czasopisma",
|
||||||
|
lLevel=0,
|
||||||
|
webpage=start}
|
||||||
|
putStrLn "Program started"
|
||||||
|
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|
||||||
|
putStrLn "Page sucesfully crawled"
|
@ -5,8 +5,8 @@ description: Please see README.md
|
|||||||
homepage: http://github.com/name/project
|
homepage: http://github.com/name/project
|
||||||
license: Proprietary
|
license: Proprietary
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Your name here
|
author: Szymon Parafiński
|
||||||
maintainer: your.address@example.com
|
maintainer: szypar@st.amu.edu.pl
|
||||||
-- copyright:
|
-- copyright:
|
||||||
category: Web
|
category: Web
|
||||||
build-type: Simple
|
build-type: Simple
|
||||||
@ -20,6 +20,7 @@ library
|
|||||||
, HTTP
|
, HTTP
|
||||||
, hxt
|
, hxt
|
||||||
, hxt-http
|
, hxt-http
|
||||||
|
, hxt-curl
|
||||||
, hxt-xpath
|
, hxt-xpath
|
||||||
, MissingH
|
, MissingH
|
||||||
, monad-logger
|
, monad-logger
|
||||||
@ -54,12 +55,25 @@ executable almanachmuszyny
|
|||||||
build-depends: base
|
build-depends: base
|
||||||
, hxt
|
, hxt
|
||||||
, hxt-xpath
|
, hxt-xpath
|
||||||
|
, hxt-curl
|
||||||
, MissingH
|
, MissingH
|
||||||
, regex-posix
|
, regex-posix
|
||||||
, shadow-library
|
, shadow-library
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
executable czasopisma
|
||||||
|
hs-source-dirs: app
|
||||||
|
main-is: czasopisma.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
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
location: https://github.com/name/project
|
location: https://git.wmi.amu.edu.pl/s444018/twilight-library
|
||||||
|
Loading…
Reference in New Issue
Block a user