forked from filipg/twilight-library
Add files
This commit is contained in:
parent
8883a924b4
commit
07a854f8e2
@ -33,7 +33,7 @@ import Data.Tree.NTree.TypeDefs
|
|||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Control.Monad.Trans
|
import Control.Monad.Trans
|
||||||
import Text.XML.HXT.XPath
|
import Text.XML.HXT.XPath
|
||||||
-- import Text.XML.HXT.Curl
|
import Text.XML.HXT.Curl
|
||||||
import Text.XML.HXT.HTTP
|
import Text.XML.HXT.HTTP
|
||||||
|
|
||||||
import Text.Regex.TDFA
|
import Text.Regex.TDFA
|
||||||
@ -64,8 +64,8 @@ downloadDocument = readFromDocument [withParseHTML yes,
|
|||||||
withEncodingErrors no,
|
withEncodingErrors no,
|
||||||
withPreserveComment yes,
|
withPreserveComment yes,
|
||||||
withStrictInput yes,
|
withStrictInput yes,
|
||||||
withHTTP []
|
-- withHTTP,
|
||||||
-- withCurl [("curl--user-agent","AMU Digital Libraries Indexing Agent")]
|
withCurl [("curl--user-agent","AMU Digital Libraries Indexing Agent")]
|
||||||
]
|
]
|
||||||
|
|
||||||
downloadDocumentWithEncoding enc = readFromDocument [withParseHTML yes,
|
downloadDocumentWithEncoding enc = readFromDocument [withParseHTML yes,
|
||||||
@ -73,13 +73,13 @@ downloadDocumentWithEncoding enc = readFromDocument [withParseHTML yes,
|
|||||||
withEncodingErrors no,
|
withEncodingErrors no,
|
||||||
withPreserveComment yes,
|
withPreserveComment yes,
|
||||||
withInputEncoding enc,
|
withInputEncoding enc,
|
||||||
withHTTP []]
|
-- withHTTP,
|
||||||
-- withCurl []]
|
withCurl [("curl--user-agent","AMU Digital Libraries Indexing Agent")]]
|
||||||
|
|
||||||
downloadXmlDocument = readFromDocument [withWarnings no,
|
downloadXmlDocument = readFromDocument [withWarnings no,
|
||||||
withEncodingErrors no,
|
withEncodingErrors no,
|
||||||
withHTTP []]
|
-- withHTTP,
|
||||||
-- withCurl [] ]
|
withCurl [("curl--user-agent","AMU Digital Libraries Indexing Agent")]]
|
||||||
|
|
||||||
|
|
||||||
data ShadowLibrary = ShadowLibrary { logoUrl :: Maybe String,
|
data ShadowLibrary = ShadowLibrary { logoUrl :: Maybe String,
|
||||||
|
45
app/otwarteczasopismauam.hs
Normal file
45
app/otwarteczasopismauam.hs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
{-# 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 = extractLinksWithText "//h3[@class='media-heading']/a"
|
||||||
|
>>> first (arr (++"/issue/archive"))
|
||||||
|
>>> first (extractLinksWithText "//*[@class='media-heading']/a"
|
||||||
|
>>> first (extractLinksWithText "//*[@class='media-heading']/a"
|
||||||
|
>>> first (extractLinks "//div[@class='download']/a")))
|
||||||
|
|
||||||
|
|
||||||
|
toShadowItem :: (((String, String), String), String) -> ShadowItem
|
||||||
|
toShadowItem (((url, articleTitle), yearlyTitle), journalTitle) =
|
||||||
|
(defaultShadowItem url title) {
|
||||||
|
originalDate = Just date,
|
||||||
|
itype = "periodical",
|
||||||
|
format = Just "pdf",
|
||||||
|
finalUrl = url
|
||||||
|
}
|
||||||
|
where title = replace "\n" "" (replace "\t" "" (journalTitle ++ " " ++ yearlyTitle ++ " " ++ articleTitle))
|
||||||
|
date = getDate yearlyTitle
|
||||||
|
|
||||||
|
getDate yearlyTitle =
|
||||||
|
case yearlyTitle =~~ "(19[0-9][0-9]|20[0-9][0-9])" :: Maybe [[String]] of
|
||||||
|
Just [[_, year]] -> year
|
||||||
|
otherwise -> error $ "unexpected text: " ++ yearlyTitle
|
||||||
|
|
||||||
|
|
||||||
|
main = do
|
||||||
|
let start = "https://pressto.amu.edu.pl"
|
||||||
|
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
||||||
|
lname="Otwarte Czasopisma Naukowe UAM",
|
||||||
|
abbrev="OtwCzasNaukUAM",
|
||||||
|
lLevel=0,
|
||||||
|
webpage=start}
|
||||||
|
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|
@ -19,6 +19,7 @@ library
|
|||||||
build-depends: base >= 4.7 && < 5
|
build-depends: base >= 4.7 && < 5
|
||||||
, HTTP
|
, HTTP
|
||||||
, hxt
|
, hxt
|
||||||
|
, hxt-curl
|
||||||
, hxt-http
|
, hxt-http
|
||||||
, hxt-xpath
|
, hxt-xpath
|
||||||
, MissingH
|
, MissingH
|
||||||
@ -59,6 +60,18 @@ executable almanachmuszyny
|
|||||||
, shadow-library
|
, shadow-library
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
executable otwarteczasopismauam
|
||||||
|
hs-source-dirs: app
|
||||||
|
main-is: otwarteczasopismauam.hs
|
||||||
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||||
|
build-depends: base
|
||||||
|
, hxt
|
||||||
|
, hxt-xpath
|
||||||
|
, hxt-curl
|
||||||
|
, MissingH
|
||||||
|
, regex-posix
|
||||||
|
, shadow-library
|
||||||
|
default-language: Haskell2010
|
||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
|
Loading…
Reference in New Issue
Block a user