Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
6b2ba28ba6 | |||
d35c818d4c | |||
210b80656e | |||
73c2bdd034 | |||
aab2421c7a |
2
.gitignore
vendored
2
.gitignore
vendored
@ -70,3 +70,5 @@ indeks
|
|||||||
zinelibrary
|
zinelibrary
|
||||||
archiveorg2
|
archiveorg2
|
||||||
.stack-work
|
.stack-work
|
||||||
|
.idea/
|
||||||
|
stack.yaml.lock
|
||||||
|
@ -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,8 @@ downloadDocument = readFromDocument [withParseHTML yes,
|
|||||||
withEncodingErrors no,
|
withEncodingErrors no,
|
||||||
withPreserveComment yes,
|
withPreserveComment yes,
|
||||||
withStrictInput yes,
|
withStrictInput yes,
|
||||||
withHTTP []
|
-- 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 +73,13 @@ downloadDocumentWithEncoding enc = readFromDocument [withParseHTML yes,
|
|||||||
withEncodingErrors no,
|
withEncodingErrors no,
|
||||||
withPreserveComment yes,
|
withPreserveComment yes,
|
||||||
withInputEncoding enc,
|
withInputEncoding enc,
|
||||||
withHTTP []]
|
-- 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,
|
||||||
|
61
app/miastobierun.hs
Normal file
61
app/miastobierun.hs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
extractLinksWithTitleAndText xpathCondition = (downloadDocument &&& this)
|
||||||
|
>>> first (getXPathTrees xpathCondition
|
||||||
|
>>> (getAttrValue "href"
|
||||||
|
&&& getAttrValue "title"
|
||||||
|
&&& (listA (deep isText >>> getText)
|
||||||
|
>>> arr (intercalate " "))))
|
||||||
|
>>> arr rotateSecTh
|
||||||
|
>>> first expandURIFixed
|
||||||
|
|
||||||
|
--extractRecords = extractCustomLinks "//tr[@class=''] | //tr[@class='_a']" "//td[@cell-header='Nazwa pliku']/a" "//td[@class='size']"
|
||||||
|
extractRecords = extractLinksWithTitleAndText "//td[not(contains(@cell-header,'Nazwa pliku'))]/a[contains(@href,'.pdf') and @target='DownloadWin']"
|
||||||
|
|
||||||
|
toShadowItem :: (String, (String, String)) -> ShadowItem
|
||||||
|
toShadowItem (url, (info, articleTitle)) =
|
||||||
|
(defaultShadowItem url title) {
|
||||||
|
originalDate = Just date,
|
||||||
|
itype = "periodical",
|
||||||
|
finalUrl = url,
|
||||||
|
format = format,
|
||||||
|
description = Just desc,
|
||||||
|
lang = Just "pol"
|
||||||
|
}
|
||||||
|
where title = replace "\r\n \r\n Plik: " "" articleTitle
|
||||||
|
desc = "Article nr: " ++ getArticleNr title ++ " Size: " ++ getFileSize info
|
||||||
|
date = getDate title
|
||||||
|
format = extractFormat url
|
||||||
|
|
||||||
|
getDate title =
|
||||||
|
case title =~~ "(19[0-9][0-9]|20[0-9][0-9])" :: Maybe [[String]] of
|
||||||
|
Just [[_, year]] -> year
|
||||||
|
otherwise -> "No date for: " ++ title
|
||||||
|
|
||||||
|
getArticleNr title =
|
||||||
|
case title =~~ "([0-9][0-9]/)" :: Maybe [[String]] of
|
||||||
|
Just [[_, nr]] -> replace "/" "" nr
|
||||||
|
otherwise -> "No article nr for: " ++ title
|
||||||
|
|
||||||
|
getFileSize title =
|
||||||
|
case title =~~ "(Rozmiar: [0-9]+.[0-9]+[A-Z]+)" :: Maybe [[String]] of
|
||||||
|
Just [[_, size]] -> replace "Rozmiar: " "" size
|
||||||
|
otherwise -> "No file size for: " ++ title
|
||||||
|
|
||||||
|
main = do
|
||||||
|
let start = "https://www.bierun.pl/mieszkancy/archiwum"
|
||||||
|
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
||||||
|
lname="Miasto Bieruń",
|
||||||
|
abbrev="Bieruń",
|
||||||
|
lLevel=0,
|
||||||
|
webpage=start}
|
||||||
|
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|
@ -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: Adam Osiowy
|
||||||
maintainer: your.address@example.com
|
maintainer: adaosi@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,6 +55,20 @@ executable almanachmuszyny
|
|||||||
build-depends: base
|
build-depends: base
|
||||||
, hxt
|
, hxt
|
||||||
, hxt-xpath
|
, hxt-xpath
|
||||||
|
, hxt-curl
|
||||||
|
, MissingH
|
||||||
|
, regex-posix
|
||||||
|
, shadow-library
|
||||||
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
executable miastobierun
|
||||||
|
hs-source-dirs: app
|
||||||
|
main-is: miastobierun.hs
|
||||||
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||||
|
build-depends: base
|
||||||
|
, hxt
|
||||||
|
, hxt-xpath
|
||||||
|
, hxt-curl
|
||||||
, MissingH
|
, MissingH
|
||||||
, regex-posix
|
, regex-posix
|
||||||
, shadow-library
|
, shadow-library
|
||||||
@ -62,4 +77,4 @@ executable almanachmuszyny
|
|||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
location: https://github.com/name/project
|
location: https://git.wmi.amu.edu.pl/s444452/twilight-library
|
||||||
|
Loading…
Reference in New Issue
Block a user