pilu/src/Main.hs

35 lines
944 B
Haskell
Raw Normal View History

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 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 ()
2019-04-07 18:08:22 +02:00
main = do
invocation <- invoked
case invocation of
Inventory -> show <$> getCurrentState >>= putStrLn
Schedule -> putStrLn "schedule"
Version version -> putStrLn version >> exitSuccess