forked from filipg/twilight-library
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
0114a102d4 | |||
1f23d94e7c | |||
953d7242e8 | |||
8883a924b4 |
@ -11,11 +11,14 @@ import Data.List.Utils (replace)
|
|||||||
import Text.Regex.Posix
|
import Text.Regex.Posix
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
|
|
||||||
extractRecords = extractLinksWithText "//a[@class='roczniki']"
|
|
||||||
>>> second (arr $ replace "\r\n " "")
|
|
||||||
>>> first (arr ((++"tr") . init))
|
|
||||||
>>> first (extractLinksWithText "//li/a[contains(@href,'.pdf')]")
|
|
||||||
|
|
||||||
|
extractRecords = extractLinksWithText "//a[@class='roczniki']" -- pary adres-tytuł
|
||||||
|
>>> second (arr $ replace "\r\n " " ") -- czyścimy drugi element pary, czyli tytuł z niepotrzebnych białych znaków
|
||||||
|
>>> first (arr ((++"tr") . init)) -- modyfikujemy pierwszy element pary, czyli adres URL
|
||||||
|
>>> first (extractLinksWithText "//li/a[contains(@href,'.pdf')]") -- pobieramy stronę z adresu URL i wyciągamy linki z tej strony pasujące do wyrażenia XPathowego
|
||||||
|
-- ostatecznie wyjdą trójki ((adres URL, tytuł artykułu), tytuł rocznika)
|
||||||
|
|
||||||
|
-- ... a tutaj te trójki przerabiamy do docelowej struktury ShadowItem
|
||||||
toShadowItem :: ((String, String), String) -> ShadowItem
|
toShadowItem :: ((String, String), String) -> ShadowItem
|
||||||
toShadowItem ((url, articleTitle), yearlyTitle) =
|
toShadowItem ((url, articleTitle), yearlyTitle) =
|
||||||
(defaultShadowItem url title) {
|
(defaultShadowItem url title) {
|
||||||
|
39
app/teatrLalek.hs
Normal file
39
app/teatrLalek.hs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
{-# LANGUAGE Arrows, NoMonomorphismRestriction #-}
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
extractRecords = extractLinks "//a[contains(@href, '.pdf')]"
|
||||||
|
|
||||||
|
|
||||||
|
toShadowItem :: String -> ShadowItem
|
||||||
|
toShadowItem url =
|
||||||
|
(defaultShadowItem url title) {
|
||||||
|
originalDate = Just date,
|
||||||
|
itype = "periodical",
|
||||||
|
format = Just "pdf",
|
||||||
|
finalUrl = url
|
||||||
|
}
|
||||||
|
where
|
||||||
|
date = last $ getAllTextMatches $ url =~ "(19[0-9][0-9]|20[0-9][0-9])" :: String
|
||||||
|
titleToProcess = last $ getAllTextMatches $ url =~ "/[a-zA-Z ]+[-_]" :: String
|
||||||
|
title = titleToProcess =~ "[a-zA-Z ]+" :: String
|
||||||
|
|
||||||
|
|
||||||
|
main = do
|
||||||
|
let start = "http://polunima.pl/teatr-lalek/"
|
||||||
|
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
||||||
|
lname="Teatr Lalek",
|
||||||
|
abbrev="Teatr",
|
||||||
|
lLevel=0,
|
||||||
|
webpage=start}
|
||||||
|
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|
@ -34,18 +34,19 @@ library
|
|||||||
, tz
|
, tz
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
-- executable maly-modelarz-exe
|
executable teatrLalek
|
||||||
-- hs-source-dirs: app
|
hs-source-dirs: app
|
||||||
-- main-is: malymodelarz.hs
|
main-is: teatrLalek.hs
|
||||||
-- ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||||
-- build-depends: base
|
build-depends: base
|
||||||
-- , hxt
|
, hxt
|
||||||
-- , hxt-curl
|
, hxt-curl
|
||||||
-- , hxt-xpath
|
, hxt-xpath
|
||||||
-- , MissingH
|
, MissingH
|
||||||
-- , regex-posix
|
, regex-posix
|
||||||
-- , shadow-library
|
, shadow-library
|
||||||
-- default-language: Haskell2010
|
, regex-tdfa
|
||||||
|
default-language: Haskell2010
|
||||||
|
|
||||||
executable almanachmuszyny
|
executable almanachmuszyny
|
||||||
hs-source-dirs: app
|
hs-source-dirs: app
|
||||||
|
Loading…
Reference in New Issue
Block a user