forked from filipg/twilight-library
Zrobiona zamiana nazwy miesiaca na wartosc liczbowa.
This commit is contained in:
parent
79dede34f5
commit
bc3ebf2eaa
@ -11,9 +11,43 @@ import Data.List.Utils (replace)
|
||||
import Text.Regex.Posix
|
||||
import Text.Printf
|
||||
|
||||
import Data.Char (toLower)
|
||||
|
||||
-- extractRecords = extractLinksWithText "(//a[@class='magazine-list__year-item'])[last()]" -- pary adres-tytuł
|
||||
extractRecords = extractLinksWithText "//a[@class='magazine-list__year-item']" -- pary adres-tytuł
|
||||
class Nothingish a where
|
||||
nada :: a
|
||||
instance Nothingish [a] where
|
||||
nada = []
|
||||
|
||||
eliminate :: (Nothingish a) => Maybe a -> a
|
||||
eliminate (Just a) = a
|
||||
eliminate Nothing = nada
|
||||
|
||||
toLowerString :: [Char] -> [Char]
|
||||
toLowerString str = [ toLower x | x <- str]
|
||||
|
||||
mToString :: Maybe String -> String
|
||||
mToString n
|
||||
| n == Nothing = ""
|
||||
| otherwise = eliminate n
|
||||
|
||||
extractMonth :: String -> String
|
||||
extractMonth n =
|
||||
case n =~~ ("[A-za-z]+" :: String) of
|
||||
Just month -> mToString (baseMonthNameToNumber (toLowerString month))
|
||||
otherwise -> ""
|
||||
|
||||
mExtractYear :: String -> String
|
||||
mExtractYear n =
|
||||
case n =~~ ("(1[6789]|20)[0-9][0-9]" :: String) of
|
||||
Just year -> year
|
||||
otherwise -> ""
|
||||
|
||||
changeDate :: String -> String
|
||||
changeDate a = mExtractYear a ++ "-" ++ extractMonth a
|
||||
|
||||
|
||||
extractRecords = extractLinksWithText "(//a[@class='magazine-list__year-item'])[last()]" -- pary adres-tytuł
|
||||
--extractRecords = extractLinksWithText "//a[@class='magazine-list__year-item']" -- pary adres-tytuł
|
||||
>>> second (arr $ replace "\r\n " "") -- czyścimy drugi element pary, czyli tytuł z niepotrzebnych białych znaków
|
||||
>>> second (arr $ replace " " "") -- czyścimy drugi element pary, czyli tytuł z niepotrzebnych białych znaków
|
||||
-- >>> first (arr ((++"tr") . init)) -- modyfikujemy pierwszy element pary, czyli adres URL
|
||||
@ -24,6 +58,7 @@ extractRecords = extractLinksWithText "//a[@class='magazine-list__year-item']"
|
||||
>>> second (arr $ replace "\r\n " "")
|
||||
-- >>> first (arr $ replace "//" "/")
|
||||
)
|
||||
>>> second (arr $ changeDate)
|
||||
) -- 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)
|
||||
|
||||
@ -52,4 +87,4 @@ main = do
|
||||
abbrev="EP",
|
||||
lLevel=0,
|
||||
webpage=start}
|
||||
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|
||||
extractItemsStartingFromUrl shadowLibrary start (extractRecords)-- >>> arr toShadowItem)
|
||||
|
Loading…
Reference in New Issue
Block a user