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
|
||||
archiveorg2
|
||||
.stack-work
|
||||
.idea/
|
||||
stack.yaml.lock
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
license: Proprietary
|
||||
license-file: LICENSE
|
||||
author: Adam Osiowy
|
||||
maintainer: adaosi@st.amu.edu.pl
|
||||
author: Your name here
|
||||
maintainer: your.address@example.com
|
||||
-- copyright:
|
||||
category: Web
|
||||
build-type: Simple
|
||||
@ -20,7 +20,6 @@ library
|
||||
, HTTP
|
||||
, hxt
|
||||
, hxt-http
|
||||
, hxt-curl
|
||||
, hxt-xpath
|
||||
, MissingH
|
||||
, monad-logger
|
||||
@ -55,20 +54,6 @@ executable almanachmuszyny
|
||||
build-depends: base
|
||||
, hxt
|
||||
, 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
|
||||
, regex-posix
|
||||
, shadow-library
|
||||
@ -77,4 +62,4 @@ executable miastobierun
|
||||
|
||||
source-repository head
|
||||
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