This commit is contained in:
AdamOsiowy123 2022-04-09 20:38:35 +02:00
parent 8883a924b4
commit aab2421c7a
4 changed files with 60 additions and 4 deletions

2
.gitignore vendored
View File

@ -70,3 +70,5 @@ indeks
zinelibrary
archiveorg2
.stack-work
.idea/
stack.yaml.lock

View File

@ -1 +1 @@
Prioprietary.
Proprietary.

41
app/miastobierun.hs Normal file
View File

@ -0,0 +1,41 @@
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 "//td[@cell-header='Nazwa pliku']/a" -- pary adres-tytuł
>>> second (arr $ replace "\r\n" "") -- czyścimy drugi element pary, czyli tytuł z niepotrzebnych białych znaków
-- ... a tutaj te dwójki przerabiamy do docelowej struktury ShadowItem
toShadowItem :: (String, String) -> ShadowItem
toShadowItem (url, articleTitle) =
(defaultShadowItem url title) {
originalDate = Just date,
itype = "periodical",
format = Just "pdf",
finalUrl = url
}
where title = 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 = "https://www.bierun.pl/mieszkancy/archiwum"
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
lname="Miasto Bieruń",
abbrev="Bieruń",
lLevel=0,
webpage=start}
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)

View File

@ -5,8 +5,8 @@ description: Please see README.md
homepage: http://github.com/name/project
license: Proprietary
license-file: LICENSE
author: Your name here
maintainer: your.address@example.com
author: Adam Osiowy
maintainer: adaosi@st.amu.edu.pl
-- copyright:
category: Web
build-type: Simple
@ -59,7 +59,20 @@ executable almanachmuszyny
, shadow-library
default-language: Haskell2010
executable miastobierun
hs-source-dirs: app
main-is: miastobierun.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
type: git
location: https://github.com/name/project
location: https://git.wmi.amu.edu.pl/s444452/twilight-library