45 lines
1.7 KiB
Haskell
45 lines
1.7 KiB
Haskell
|
|
{-# LANGUAGE Arrows, NoMonomorphismRestriction #-}
|
|
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 "//a[@class='ramka']" -- pary adres-tytuł
|
|
|
|
>>> first (extractLinksWithText "//div/a[contains(@href, '.zip') and not (contains(@href,'text_offline.zip'))]") -- tutaj wybieramy paczki zip z plikami DjVu, jeśli byśmy chcieli bezpośrednio format DjVu wystarczy trochę zmienić zapytanie XPatha.
|
|
|
|
-- ... a tutaj te trójki przerabiamy do docelowej struktury ShadowItem
|
|
toShadowItem :: ((String, String), String) -> ShadowItem
|
|
toShadowItem ((url, articleTitle), yearlyTitle) =
|
|
(defaultShadowItem url title) {
|
|
originalDate = Just date,
|
|
itype = "periodical",
|
|
format = Just "zip",
|
|
finalUrl = url
|
|
}
|
|
where title = "Tajemnica Atari " ++ yearlyTitle ++ " " ++ (replace "\r\n" "" (replace "\r\n " "" articleTitle))
|
|
date = getDate url
|
|
|
|
getDate url =
|
|
case url =~~ "/([1-9]_9[0-9]|1[0-2]_9[0-9]|[1-9]-[1-9]_9[0-9]|1[0-2]-1[0-2]_9[0-9])/" :: Maybe [[String]] of
|
|
Just [[_, year]] -> year
|
|
otherwise -> error $ "unexpected url: " ++ url
|
|
|
|
|
|
main = do
|
|
let start = "http://krap.pl/mirrorz/atari/horror.mirage.com.pl/pixel/"
|
|
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
|
lname="Tajemnica Atari",
|
|
abbrev="TA",
|
|
lLevel=0,
|
|
webpage=start}
|
|
extractItemsStartingFromUrl shadowLibrary start (extractRecords >>> arr toShadowItem)
|