diff --git a/app/best_robot.hs b/app/best_robot.hs index e44d216..06387ee 100644 --- a/app/best_robot.hs +++ b/app/best_robot.hs @@ -12,27 +12,31 @@ import Text.Regex.Posix import Text.Printf + extractRecords = extractLinksWithText "//a[@class='title']" -- pary adres-tytuł - >>> second (arr $ replace "\r\n " "")-- czyścimy drugi element pary, czyli tytuł z niepotrzebnych białych znaków + >>> second (arr $ replace "\n\t\t\t\t\t" "")-- czyścimy drugi element pary, czyli tytuł z niepotrzebnych białych znaków >>> first (extractLinksWithText "//a[@class='obj_galley_link pdf']") -- pobieramy stronę z adresu URL i wyciągamy linki z tej strony pasujące do wyrażenia XPathowego + -- ostatecznie wyjdą trójki ((adres URL, tytuł artykułu), tytuł rocznika) +-- ... a tutaj te trójki przerabiamy do docelowej struktury ShadowItem toShadowItem :: ((String, String), String) -> ShadowItem toShadowItem ((url, articleTitle), yearlyTitle) = (defaultShadowItem url title) { - originalDate = Just yearlyTitle, + originalDate = Just date, itype = "periodical", format = Just "pdf", finalUrl = url } - where title = yearlyTitle ++ " " ++ (replace "\r\n" "" (replace "\r\n " "" articleTitle)) - date = getDate url -getDate url = - case url =~~ "/([0-9]+)/" :: Maybe [[String]] of + where title = replace "\n\t\t\t" "" yearlyTitle ++ " " ++ (replace "\n\n\t" "" (replace "\n\n\t\t\n\t" " " articleTitle)) + date = getDate yearlyTitle + +getDate yearlyTitle = + case yearlyTitle =~~ "(19[0-9][0-9]|20[0-9][0-9])" :: Maybe [[String]] of Just [[_, year]] -> year - otherwise -> error $ "unexpected url: " ++ url + otherwise -> error $ "unexpected yearlyTitle " ++ yearlyTitle main = do @@ -55,4 +59,4 @@ main = do - + \ No newline at end of file