Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
7812360ecb | |||
98e1b69b8b | |||
ebfaa72b53 | |||
a2bed0a113 |
44
app/swidnik.hs
Normal file
44
app/swidnik.hs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
{-# 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
|
||||||
|
swidnik
|
||||||
|
|
||||||
|
extractRecords = extractLinksWithText "//a/div[@src='http://www.bibliotekaswidnik.pl/images/banners/pdf_klik.jpg"']" -- pary adres-tytuł
|
||||||
|
>>> second (arr $ replace "\r\n " " ") -- czyścimy drugi element pary, czyli tytuł z niepotrzebnych białych znaków
|
||||||
|
>>> 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 ((url, articleTitle), yearlyTitle) =
|
||||||
|
(defaultShadowItem url title) {
|
||||||
|
originalDate = Just date,
|
||||||
|
itype = "periodical",
|
||||||
|
format = Just "pdf",
|
||||||
|
finalUrl = url
|
||||||
|
}
|
||||||
|
where title = "Glos " ++ yearlyTitle ++ " " ++ (replace "\r\n" "" (replace "\r\n " "" articleTitle))
|
||||||
|
date = getDate url
|
||||||
|
|
||||||
|
getDate url =
|
||||||
|
case url =~~ "/(19[0-9][0-9]|20[0-9][0-9])/" :: Maybe [[String]] of
|
||||||
|
Just [[_, year]] -> year
|
||||||
|
otherwise -> error $ "unexpected url: " ++ url
|
||||||
|
|
||||||
|
|
||||||
|
main = do
|
||||||
|
let start = "s.bibliotekaswidnik.pl/index.php/116-glos-swidnika
|
||||||
|
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
||||||
|
lname="Glos",
|
||||||
|
abbrev="Glos",
|
||||||
|
lLevel=0,
|
||||||
|
webpage=start}
|
||||||
|
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|
@ -47,9 +47,9 @@ library
|
|||||||
-- , shadow-library
|
-- , shadow-library
|
||||||
-- default-language: Haskell2010
|
-- default-language: Haskell2010
|
||||||
|
|
||||||
executable almanachmuszyny
|
executable swidnik
|
||||||
hs-source-dirs: app
|
hs-source-dirs: app
|
||||||
main-is: almanachmuszyny.hs
|
main-is: swidnik.hs
|
||||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||||
build-depends: base
|
build-depends: base
|
||||||
, hxt
|
, hxt
|
||||||
@ -62,4 +62,4 @@ executable almanachmuszyny
|
|||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
location: https://github.com/name/project
|
location: https://git.wmi.amu.edu.pl/s444354/twilight-library
|
||||||
|
Loading…
Reference in New Issue
Block a user