archiwum harserskie test

This commit is contained in:
Mariusz B 2021-04-11 12:09:01 +00:00
parent 8883a924b4
commit 0858766cc9
2 changed files with 68 additions and 0 deletions

57
app/archiwumharcerskie.hs Normal file
View File

@ -0,0 +1,57 @@
{-# 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
-- wyciaganie pdf-ow
extractRecords = extractLinksWithText "//nav//a[contains(@href,'title=Kategoria:Dokumenty')]"
>>> first (extractLinksWithText "//a[contains(@href,'title=Plik') and contains(@href,'pdf')]")
>>> first (first (extractLinksGeneralized "//div[@id='file']//iframe" "src"))
-- proby pobrania pdf i jpg
--extractRecords = extractLinksWithText "//nav//a[contains(@href,'title=Kategoria:14_WDH')]"
-- >>> first (extractLinksWithText "//a[contains(@href,'title=Plik') and (contains(@href,'pdf') or contains(@href,'jpg'))]")
-- >>> first ( first (
-- downloadDocument
-- >>> (getXPathTrees "//div[@id='file']//iframe"
-- >>> getAttrValue "src") *** (getXPathTrees "//div[@id='file']//a"
-- >>> getAttrValue "href")
-- >>> first (expandURIFixed)
-- ))
toShadowItem :: ((String, String), String) -> ShadowItem
toShadowItem ((url, fileTitle), emptyTmp) =
(defaultShadowItem url title) {
originalDate = date,
itype = "periodical",
format = ext,
finalUrl = url
}
where title = "Archiwum Harcerskie - " ++ fileTitle
date = extractDate url
ext = extractFormat url
extractDate :: String -> Maybe String
extractDate n =
case n =~~ ("(((19[0-9]{2})|(2[0-2]{1}[0-9]{2}))(((-[0-1]{1}[0-9]{1}-[0-9]{2})|)|((-[0-1]{1}[0-9]{1}[^0-9][ _-]{1}))))" :: String) of
Just date -> Just date
otherwise -> Nothing
main = do
let start = "http://archiwumharcerskie.pl/index.php?title=Strona_główna"
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
lname="Archiwum Harcerskie",
abbrev="ArchHarc",
lLevel=0,
webpage=start}
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
-- extractItemsStartingFromUrl shadowLibrary start (extractRecords)

View File

@ -59,6 +59,17 @@ executable almanachmuszyny
, shadow-library , shadow-library
default-language: Haskell2010 default-language: Haskell2010
executable archiwumharcerskie
hs-source-dirs: app
main-is: archiwumharcerskie.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, hxt
, hxt-xpath
, MissingH
, regex-posix
, shadow-library
default-language: Haskell2010
source-repository head source-repository head
type: git type: git