35 lines
944 B
Haskell
35 lines
944 B
Haskell
module Main where
|
|
|
|
import CLI (Invocation(..), invoked)
|
|
import CSV (Row, parse)
|
|
import Data.Time (UTCTime(..), getCurrentTime)
|
|
import Event (Event)
|
|
import Medicine (Medicine, Pharmacy, pharmacy)
|
|
import System.Exit (exitFailure, exitSuccess)
|
|
import Timeline (State, currentState)
|
|
|
|
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
|
|
|
|
getPharmacy :: String -> IO Pharmacy
|
|
getPharmacy = fmap pharmacy . readCSV
|
|
|
|
getCurrentState :: IO State
|
|
getCurrentState =
|
|
currentState
|
|
<$> (utctDay <$> getCurrentTime)
|
|
<*> getPharmacy "medicine.csv"
|
|
<*> readCSV "timeline.csv"
|
|
|
|
main :: IO ()
|
|
main = do
|
|
invocation <- invoked
|
|
case invocation of
|
|
Inventory -> show <$> getCurrentState >>= putStrLn
|
|
Schedule -> putStrLn "schedule"
|
|
Version version -> putStrLn version >> exitSuccess
|