forked from filipg/twilight-library
Compare commits
No commits in common. "master" and "master" have entirely different histories.
2
.gitignore
vendored
2
.gitignore
vendored
@ -70,5 +70,3 @@ 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,
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
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: Adam Osiowy
|
author: Your name here
|
||||||
maintainer: adaosi@st.amu.edu.pl
|
maintainer: your.address@example.com
|
||||||
-- copyright:
|
-- copyright:
|
||||||
category: Web
|
category: Web
|
||||||
build-type: Simple
|
build-type: Simple
|
||||||
@ -20,7 +20,6 @@ library
|
|||||||
, HTTP
|
, HTTP
|
||||||
, hxt
|
, hxt
|
||||||
, hxt-http
|
, hxt-http
|
||||||
, hxt-curl
|
|
||||||
, hxt-xpath
|
, hxt-xpath
|
||||||
, MissingH
|
, MissingH
|
||||||
, monad-logger
|
, monad-logger
|
||||||
@ -55,20 +54,6 @@ 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
|
||||||
@ -77,4 +62,4 @@ executable miastobierun
|
|||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
location: https://git.wmi.amu.edu.pl/s444452/twilight-library
|
location: https://github.com/name/project
|
||||||
|
Loading…
Reference in New Issue
Block a user