forked from filipg/twilight-library
Compare commits
No commits in common. "master" and "master" have entirely different histories.
@ -1,67 +0,0 @@
|
||||
|
||||
{-# LANGUAGE Arrows, NoMonomorphismRestriction, TemplateHaskell, QuasiQuotes #-}
|
||||
import ShadowLibrary.Core
|
||||
|
||||
import Text.XML.HXT.Core
|
||||
import Text.XML.HXT.XPath
|
||||
|
||||
import Data.List
|
||||
import Data.List.Utils (replace)
|
||||
|
||||
import Text.Printf
|
||||
|
||||
import Control.Lens.Regex.Text
|
||||
import Control.Lens ((^?))
|
||||
import qualified Data.Text as T
|
||||
|
||||
getLinkAndText xpathCondition = proc doc -> do
|
||||
xpathTrees <- getXPathTrees xpathCondition -< doc
|
||||
name <- getElemName -< xpathTrees
|
||||
txt <- (getXPathTrees "//a/../text()" >>> listA (deep isText >>> getText) >>> arr (intercalate " ")) -< xpathTrees
|
||||
href <- (getXPathTrees "//a" >>> getAttrValue "href") -< xpathTrees
|
||||
returnA -< (href, txt)
|
||||
|
||||
|
||||
extractNestedLinksWithText xpathCondition = proc url -> do
|
||||
doc <- downloadDocument -< url
|
||||
(link, text) <- getLinkAndText xpathCondition -< doc
|
||||
uriFixed <- expandURIFixed -< (link, url)
|
||||
returnA -< (uriFixed, text)
|
||||
|
||||
|
||||
extractRecords = proc startUrl -> do
|
||||
(catUrl, catText) <- extractLinksWithText "//aside[@class='widget widget_maxmegamenu']//a[@class='mega-menu-link']" -< startUrl -- pary adres-tytuł podstrony
|
||||
(collUrl, collText) <- (extractLinksWithText "//aside[@class='widget widget_maxmegamenu']//a[@class='mega-menu-link']") -< catUrl -- pobieramy podstronę kategorii i kolejne podstrony z menu
|
||||
(relUrl, relText) <- (extractNestedLinksWithText "//big[a[contains(@href,'.pdf')]]") -< collUrl -- pobieramy stronę z wydaniami z danej kolekcji i linki do PDFów
|
||||
returnA -< (relUrl, relText, collText, catText) -- ostatecznie wyjdą krotki (adres URL PDFa wydania, tytuł wydania, tytuł zbioru, tytuł kategorii)
|
||||
|
||||
cleanReleaseTitle :: String -> String
|
||||
cleanReleaseTitle = proc text -> do
|
||||
endCleaned <- replace " |\160" "" -< text
|
||||
nbspCleaned <- replace "\160" " " -< endCleaned
|
||||
res <- replace "\8211 " "" -< nbspCleaned
|
||||
returnA -< res
|
||||
|
||||
-- ... a tutaj te krotki przerabiamy do docelowej struktury ShadowItem
|
||||
toShadowItem :: (String, String, String, String) -> ShadowItem
|
||||
toShadowItem (url, releaseTitle, collectionTitle, categoryTitle) =
|
||||
(defaultShadowItem url title) {
|
||||
originalDate = T.unpack <$> date,
|
||||
itype = "periodical",
|
||||
format = Just "pdf",
|
||||
finalUrl = url
|
||||
}
|
||||
where title = categoryTitle ++ (" " ++ arr cleanReleaseTitle releaseTitle)
|
||||
date = getDate $ T.pack $ releaseTitle
|
||||
|
||||
|
||||
getDate txt = txt ^? [regex|19[0-9][0-9]|20[0-9][0-9]|] . match
|
||||
|
||||
main = do
|
||||
let start = "http://zborbielawa.pl/archiwum/"
|
||||
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
||||
lname="Zbór Bielawa",
|
||||
abbrev="ZboBiel",
|
||||
lLevel=0,
|
||||
webpage=start}
|
||||
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|
@ -60,22 +60,6 @@ executable almanachmuszyny
|
||||
default-language: Haskell2010
|
||||
|
||||
|
||||
executable zborbielawa
|
||||
hs-source-dirs: app
|
||||
main-is: ZborBielawa.hs
|
||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||
build-depends: base
|
||||
, hxt
|
||||
, hxt-xpath
|
||||
, MissingH
|
||||
, regex-posix
|
||||
, shadow-library
|
||||
, lens-regex-pcre
|
||||
, lens
|
||||
, text
|
||||
default-language: Haskell2010
|
||||
|
||||
|
||||
source-repository head
|
||||
type: git
|
||||
location: https://github.com/name/project
|
||||
|
@ -1,9 +1,5 @@
|
||||
flags: {}
|
||||
packages:
|
||||
- '.'
|
||||
extra-deps: [
|
||||
hxt-xpath-9.1.2.2,
|
||||
lens-regex-pcre-1.1.0.0,
|
||||
pcre-light-0.4.1.0
|
||||
]
|
||||
resolver: lts-11.9
|
||||
extra-deps: [hxt-xpath-9.1.2.2]
|
||||
resolver: lts-11.9
|
||||
|
@ -1,33 +0,0 @@
|
||||
# This file was autogenerated by Stack.
|
||||
# You should not edit this file by hand.
|
||||
# For more information, please see the documentation at:
|
||||
# https://docs.haskellstack.org/en/stable/lock_files
|
||||
|
||||
packages:
|
||||
- completed:
|
||||
hackage: hxt-xpath-9.1.2.2@sha256:9cd590ae93a04573db8f90fa4094625ebd97dded45da7667c577ce6b38a42900,1999
|
||||
pantry-tree:
|
||||
size: 2225
|
||||
sha256: aee2f75974e868ff429b8ff349a29667536c60397098f5dfedc968d1951511bb
|
||||
original:
|
||||
hackage: hxt-xpath-9.1.2.2
|
||||
- completed:
|
||||
hackage: lens-regex-pcre-1.1.0.0@sha256:a6053fefae59f6b53b4741e5a75c5fae350af80dbf62e8673b565e1c3f34f8b9,2209
|
||||
pantry-tree:
|
||||
size: 630
|
||||
sha256: 84a02d84433d92c5e2a9a7bfd662244be607b4004c7d4d6fd1ba53adbc655022
|
||||
original:
|
||||
hackage: lens-regex-pcre-1.1.0.0
|
||||
- completed:
|
||||
hackage: pcre-light-0.4.1.0@sha256:4902ef06b037fd79448c7a63a65c1a4a1bf0bbc15ea7e67e71d52ec995e18460,1868
|
||||
pantry-tree:
|
||||
size: 467
|
||||
sha256: 5e5f8d948ba577d4d838895ccb3533c6ef9876ef60884dae8342a77934cc2ec2
|
||||
original:
|
||||
hackage: pcre-light-0.4.1.0
|
||||
snapshots:
|
||||
- completed:
|
||||
size: 507596
|
||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/11/9.yaml
|
||||
sha256: 42f472dbf06482da1b3319241f3e3b3593a45bd7d4f537d2789f21386b9b2ad3
|
||||
original: lts-11.9
|
Loading…
Reference in New Issue
Block a user