chinese-holidays-calendar/parser/Main.hs

40 lines
1.1 KiB
Haskell
Raw Permalink Normal View History

module Main where
2023-11-07 08:23:04 +08:00
import Data.Function (on)
import Data.List (isPrefixOf, sortBy)
import Main.Base
import Main.Input
import Main.Output
import System.Directory (listDirectory)
import System.FilePath ((</>))
-- Parse holiday data
-- Generate ics files
main :: IO ()
main = do
-- read files
filesInDir <- listDirectory "./data"
let files = filter ("20" `isPrefixOf`) filesInDir
contents <- mapM (readFile . ("./data" </>)) files
-- parse data
2023-11-07 08:23:04 +08:00
let calendarYearly = zipWith parseFile files contents
debug calendarYearly
-- write files
2023-11-07 08:23:04 +08:00
let calendar = calendarYearly >>= join
writeFile "./docs/index.html" $ generate calendar Both
2023-11-07 08:23:04 +08:00
writeFile "./docs/main.ics" $ generate calendar Both
writeFile "./docs/rest.ics" $ generate calendar Rest
writeFile "./docs/work.ics" $ generate calendar Work
-- Log holiday data ordered by each year
2023-11-07 08:23:04 +08:00
debug :: [Yearly] -> IO ()
debug yearly =
let orderByYear = sortBy (compare `on` year) yearly
printByDate holiday = do
putStrLn $ "\nYear " ++ year holiday
mapM_ print $ sortByDate $ join holiday
in mapM_ printByDate orderByYear