forked from filipg/twilight-library
Compare commits
No commits in common. "master" and "master" have entirely different histories.
@ -1,44 +0,0 @@
|
|||||||
{-# 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 swidnik
|
executable almanachmuszyny
|
||||||
hs-source-dirs: app
|
hs-source-dirs: app
|
||||||
main-is: swidnik.hs
|
main-is: almanachmuszyny.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 swidnik
|
|||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
location: https://git.wmi.amu.edu.pl/s444354/twilight-library
|
location: https://github.com/name/project
|
||||||
|
Loading…
Reference in New Issue
Block a user