From b3032cbd44474e1eacc1c8bbb3271c92229b9808 Mon Sep 17 00:00:00 2001 From: MikolajPaterka Date: Tue, 12 Apr 2022 23:00:34 +0200 Subject: [PATCH] bip --- README.md | 7 +++++ app/test.hs | 71 ++++++++++++++++++++++++++++++++++++++++++++ newFiles.json | 1 + oldFiles.json | 1 + shadow-library.cabal | 11 +++++++ stack.yaml.lock | 19 ++++++++++++ 6 files changed, 110 insertions(+) create mode 100644 README.md create mode 100644 app/test.hs create mode 100644 newFiles.json create mode 100644 oldFiles.json create mode 100644 stack.yaml.lock diff --git a/README.md b/README.md new file mode 100644 index 0000000..1fb87f6 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Strona +Strona: https://bip.um.gdynia.pl/wyszukiwarka-uchwal-rady-miasta,7485/wyszukiwarka-uchwal,504923 + + +# Wyniki +Lata 1990 - 1999 -> oldFiles.json +Lata 2000 - 2022 -> newFiles.json \ No newline at end of file diff --git a/app/test.hs b/app/test.hs new file mode 100644 index 0000000..b29c751 --- /dev/null +++ b/app/test.hs @@ -0,0 +1,71 @@ + +{-# LANGUAGE Arrows, NoMonomorphismRestriction #-} +import ShadowLibrary.Core + +import Text.XML.HXT.Core +import Text.XML.HXT.XPath +import Data.List +import Data.List.Utils (replace) + +import Text.Regex.Posix +import Text.Printf +import System.IO + + +extractYears = extractLinksWithText "//div[@class='inner clearfix']//div[@class='row']//div[@class='col-sm-6']//ul//li//a" -- pary adres-tytuł +runYearsExtractor url = runX $ (arr (const url) >>> setTraceLevel 1 >>> extractYears) + +extractNewFiles = extractLinksWithText "//a[@title='Pobierz plik']" -- pary adres-tytuł +runNewFilesExtractor url = runX $ (arr (const url) >>> setTraceLevel 1 >>> extractNewFiles) + +extractOldFiles = extractLinksWithText "//div[@class='content']//div[@class='inner clearfix']//ul//li//a" -- pary adres-tytuł +runOldFilesExtractor url = runX $ (arr (const url) >>> setTraceLevel 1 >>> extractOldFiles) + +--367-376 +extractOldYears = extractLinksWithText "//nav[@class='nav-left']//ul//li[@class='single-article']/a" -- pary adres-tytuł +runOldYearsExtractor url = runX $ (arr (const url) >>> setTraceLevel 1 >>> extractOldYears) + +mapToUrl :: ([Char], [Char]) -> [Char] +mapToUrl (url, title) = url + +merge [] ys = ys +merge (x:xs) ys = x:merge ys xs + +repeatNTimes 0 = return [] +repeatNTimes n = do + let link = "https://bip.um.gdynia.pl/module/Contents/controller/Default/action/loadSubcategory/subcategory_id/" ++ show (377-n) + items <- runOldYearsExtractor link + let urls = map mapToUrl items + recursive <- repeatNTimes (n-1) + let results = merge urls recursive + return results + +flatten :: [[a]] -> [a] +flatten xs = (\z n -> foldr (\x y -> foldr z y x) n xs) (:) [] + +getAllPages url = do + items <- runYearsExtractor url + let urls = map mapToUrl items + newFiles <- mapM runNewFilesExtractor urls + let fileUrls = map mapToUrl (flatten newFiles) + return fileUrls + +getOldFiles = do + oldPages <- repeatNTimes 10 + --let sub = take 2 oldPages + oldFiles <- mapM runOldFilesExtractor oldPages + let fileUrls = map mapToUrl (flatten oldFiles) + return fileUrls + +main = do + let start = "https://bip.um.gdynia.pl/wyszukiwarka-uchwal-rady-miasta,7485/wyszukiwarka-uchwal,504923" + oldResults <- getOldFiles + oldF <- openFile "oldFiles.json" WriteMode + hPrint oldF oldResults + hClose oldF + + --print (length results) + newResults <- getAllPages start + newF <- openFile "newFiles.json" WriteMode + hPrint newF newResults + hClose newF \ No newline at end of file diff --git a/newFiles.json b/newFiles.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/newFiles.json @@ -0,0 +1 @@ +[] diff --git a/oldFiles.json b/oldFiles.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/oldFiles.json @@ -0,0 +1 @@ +[] diff --git a/shadow-library.cabal b/shadow-library.cabal index cd77195..c20849a 100644 --- a/shadow-library.cabal +++ b/shadow-library.cabal @@ -59,6 +59,17 @@ executable almanachmuszyny , shadow-library default-language: Haskell2010 +executable test + hs-source-dirs: app + main-is: test.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 type: git diff --git a/stack.yaml.lock b/stack.yaml.lock new file mode 100644 index 0000000..cc80ef3 --- /dev/null +++ b/stack.yaml.lock @@ -0,0 +1,19 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: +- completed: + hackage: hxt-xpath-9.1.2.2@sha256:9cd590ae93a04573db8f90fa4094625ebd97dded45da7667c577ce6b38a42900,1999 + pantry-tree: + size: 2225 + sha256: aee2f75974e868ff429b8ff349a29667536c60397098f5dfedc968d1951511bb + original: + hackage: hxt-xpath-9.1.2.2 +snapshots: +- completed: + size: 507596 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/11/9.yaml + sha256: 42f472dbf06482da1b3319241f3e3b3593a45bd7d4f537d2789f21386b9b2ad3 + original: lts-11.9