From aab2421c7a2607d86d942bec9ed40e605f5a0212 Mon Sep 17 00:00:00 2001 From: AdamOsiowy123 Date: Sat, 9 Apr 2022 20:38:35 +0200 Subject: [PATCH] init --- .gitignore | 2 ++ LICENSE | 2 +- app/miastobierun.hs | 41 +++++++++++++++++++++++++++++++++++++++++ shadow-library.cabal | 19 ++++++++++++++++--- 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 app/miastobierun.hs diff --git a/.gitignore b/.gitignore index dbc8eb0..02729a7 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,5 @@ indeks zinelibrary archiveorg2 .stack-work +.idea/ +stack.yaml.lock diff --git a/LICENSE b/LICENSE index ce328d6..2a732f9 100644 --- a/LICENSE +++ b/LICENSE @@ -1 +1 @@ -Prioprietary. \ No newline at end of file +Proprietary. \ No newline at end of file diff --git a/app/miastobierun.hs b/app/miastobierun.hs new file mode 100644 index 0000000..f73c32f --- /dev/null +++ b/app/miastobierun.hs @@ -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) diff --git a/shadow-library.cabal b/shadow-library.cabal index cd77195..3660927 100644 --- a/shadow-library.cabal +++ b/shadow-library.cabal @@ -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