Compare commits

...

32 Commits
master ... dev

Author SHA1 Message Date
Norbert Litkowski
1d077001b8 clean output 2021-04-07 23:28:39 +02:00
Norbert Litkowski
0d45d42336 Simplify return types of records extract 2021-04-07 14:38:47 +02:00
Norbert Litkowski
67344b3d61 Simplify XPath queries 2021-04-07 14:33:45 +02:00
nlitkowski
4ae00c6660 Add packages 2021-04-07 14:07:28 +02:00
Norbert Litkowski
ea12e8ac21 WIP 2021-04-07 13:38:47 +02:00
nlitkowski
5c7345957c Add language directive 2021-04-07 13:22:42 +02:00
Norbert Litkowski
0442a8c067 WIP 2021-04-07 13:19:42 +02:00
Norbert Litkowski
15c2e705b1 Add lens regex package 2021-04-07 12:43:50 +02:00
Norbert Litkowski
4ad7fce898 fix xpaths for second category 2021-04-07 12:20:34 +02:00
nlitkowski
1b7e1281f9 Merge branch 'dev' of https://git.wmi.amu.edu.pl/s440054/twilight-library into dev 2021-04-07 12:04:43 +02:00
nlitkowski
4e49f51ead change var names to more relevant ones 2021-04-07 12:04:07 +02:00
Norbert Litkowski
25c6139e81 comment 2021-04-07 04:07:53 +02:00
Norbert Litkowski
45e471a312 fix typos 2021-04-07 04:07:35 +02:00
nlitkowski
5590d3d8ce Remove test code parts 2021-04-07 04:01:42 +02:00
Norbert Litkowski
cb5948925d Fetching text 2021-04-07 03:54:56 +02:00
nlitkowski
10c06c503c WIP 2021-04-07 03:36:28 +02:00
nlitkowski
07b43649a9 WIP 2021-04-07 03:03:14 +02:00
Norbert Litkowski
eba9beb68e remove unused fns 2021-04-07 03:00:31 +02:00
nlitkowski
944d67f524 WIP 2021-04-07 02:56:44 +02:00
nlitkowski
6472697a79 WIP 2021-04-07 02:53:08 +02:00
nlitkowski
3314561a8a WIP 2021-04-07 02:41:21 +02:00
nlitkowski
e4458b5780 WIP 2021-04-07 02:39:02 +02:00
nlitkowski
141728f14f WIP 2021-04-07 02:37:50 +02:00
nlitkowski
8fd481ac15 WIP 2021-04-07 02:22:55 +02:00
nlitkowski
0fc12d23f4 WIP 2021-04-07 02:20:30 +02:00
Norbert Litkowski
974e04831c WIP 2021-04-07 02:12:02 +02:00
Norbert Litkowski
9aa0ae145b WIP 2021-04-07 00:49:14 +02:00
nlitkowski
e2aa05e511 WIP 2021-04-07 00:42:40 +02:00
nlitkowski
51020ab0bb add page name and abbrev 2021-04-07 00:07:43 +02:00
nlitkowski
27a539265d change names to appropriate 2021-04-06 23:14:12 +02:00
nlitkowski
8e8955950f fix typo 2021-04-06 23:01:51 +02:00
nlitkowski
ff3c84cec5 init robot file 2021-04-06 22:55:09 +02:00
4 changed files with 122 additions and 2 deletions

67
app/ZborBielawa.hs Normal file
View File

@ -0,0 +1,67 @@
{-# 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)

View File

@ -60,6 +60,22 @@ 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

View File

@ -1,5 +1,9 @@
flags: {}
packages:
- '.'
extra-deps: [hxt-xpath-9.1.2.2]
resolver: lts-11.9
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

33
stack.yaml.lock Normal file
View File

@ -0,0 +1,33 @@
# 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