pilu/src/Main.hs

37 lines
1.0 KiB
Haskell
Raw Normal View History

{-# LANGUAGE NamedFieldPuns #-}
module Main where
2019-04-07 18:08:22 +02:00
import CLI (Invocation(..), invoked)
import CSV (Row, parse)
import Data.Time (UTCTime(..), getCurrentTime)
import Medicine (Pharmacy, pharmacy)
2019-04-07 18:08:22 +02:00
import System.Exit (exitFailure, exitSuccess)
import Schedule (schedule)
import Timeline (State(..), stateAt)
import YAML (encode)
2019-04-07 18:08:22 +02:00
readCSV :: Row a => FilePath -> IO [a]
readCSV filePath = do
parsed <- parse filePath '\t' <$> readFile filePath
case parsed of
Left e -> (putStrLn $ show e) >> exitFailure
Right rows -> return rows
getState :: Pharmacy -> IO State
getState aPharmacy =
stateAt
2019-04-07 18:08:22 +02:00
<$> (utctDay <$> getCurrentTime)
<*> (return aPharmacy)
2019-04-07 18:08:22 +02:00
<*> readCSV "timeline.csv"
main :: IO ()
2019-04-07 18:08:22 +02:00
main = do
invocation <- invoked
display <- case invocation of
Inventory -> return $ const encode
Schedule -> return $ \ph -> encode . schedule ph
2019-04-07 18:08:22 +02:00
Version version -> putStrLn version >> exitSuccess
thePharmacy <- pharmacy <$> readCSV "medicine.csv"
theState <- getState thePharmacy
putStrLn $ display thePharmacy theState