This commit is contained in:
AdamOsiowy123 2022-04-13 19:44:53 +02:00
parent d35c818d4c
commit 6b2ba28ba6
1 changed files with 23 additions and 25 deletions

View File

@ -9,38 +9,32 @@ import Data.List.Utils (replace)
import Text.Regex.Posix import Text.Regex.Posix
import Text.Printf import Text.Printf
--extractCustomLinks xpathCondition1 = (downloadDocument &&& this) extractLinksWithTitleAndText xpathCondition = (downloadDocument &&& this)
-- >>> first (getXPathTrees xpathCondition1 >>> first (getXPathTrees xpathCondition
-- >>> (getAttrValue "href" >>> (getAttrValue "href"
-- &&& getAttrValue "title" &&& getAttrValue "title"
-- )) &&& (listA (deep isText >>> getText)
-- >>> arr rotateSecTh >>> arr (intercalate " "))))
-- >>> first expandURIFixed >>> arr rotateSecTh
extractCustomLinks xpathCondition1 xpathCondition2 xpathCondition3= (downloadDocument &&& this)
>>> first (getXPathTrees xpathCondition1
>>> first (getXPathTrees xpathCondition2 >>> (getAttrValue "href" &&& getAttrValue "title"))
>>> second (getXPathTrees xpathCondition3 >>> getAttrValue "cell-header")
)
>>> arr rotateSecThX
>>> first expandURIFixed >>> first expandURIFixed
>>> second expandURIFixed
extractRecords = extractCustomLinks "//tr[@class=''] | //tr[@class='_a']" "//td[@cell-header='Nazwa pliku']/a" "//td[@class='size']" --extractRecords = extractCustomLinks "//tr[@class=''] | //tr[@class='_a']" "//td[@cell-header='Nazwa pliku']/a" "//td[@class='size']"
--extractRecords = extractCustomLinks "//td[@cell-header='Nazwa pliku']/a" extractRecords = extractLinksWithTitleAndText "//td[not(contains(@cell-header,'Nazwa pliku'))]/a[contains(@href,'.pdf') and @target='DownloadWin']"
toShadowItem :: (String, String, String) -> ShadowItem toShadowItem :: (String, (String, String)) -> ShadowItem
toShadowItem (url, size, articleTitle) = toShadowItem (url, (info, articleTitle)) =
(defaultShadowItem url title) { (defaultShadowItem url title) {
originalDate = Just date, originalDate = Just date,
itype = "periodical", itype = "periodical",
format = Just "pdf",
finalUrl = url, finalUrl = url,
description = Just desc format = format,
description = Just desc,
lang = Just "pol"
} }
where title = "Miasto Bierun: " ++ " url: " ++ url ++ " title: " ++ articleTitle where title = replace "\r\n \r\n Plik: " "" articleTitle
date = getDate articleTitle desc = "Article nr: " ++ getArticleNr title ++ " Size: " ++ getFileSize info
desc = getArticleNr articleTitle ++ " size: " date = getDate title
format = extractFormat url
getDate title = getDate title =
case title =~~ "(19[0-9][0-9]|20[0-9][0-9])" :: Maybe [[String]] of case title =~~ "(19[0-9][0-9]|20[0-9][0-9])" :: Maybe [[String]] of
@ -49,9 +43,13 @@ getDate title =
getArticleNr title = getArticleNr title =
case title =~~ "([0-9][0-9]/)" :: Maybe [[String]] of case title =~~ "([0-9][0-9]/)" :: Maybe [[String]] of
Just [[_, nr]] -> "Article nr: " ++ (replace "/" "" nr) Just [[_, nr]] -> replace "/" "" nr
otherwise -> "No article nr for: " ++ title otherwise -> "No article nr for: " ++ title
getFileSize title =
case title =~~ "(Rozmiar: [0-9]+.[0-9]+[A-Z]+)" :: Maybe [[String]] of
Just [[_, size]] -> replace "Rozmiar: " "" size
otherwise -> "No file size for: " ++ title
main = do main = do
let start = "https://www.bierun.pl/mieszkancy/archiwum" let start = "https://www.bierun.pl/mieszkancy/archiwum"