diff options
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/Main.hs b/src/Main.hs new file mode 100644 index 0000000..9debfe1 --- /dev/null +++ b/src/Main.hs @@ -0,0 +1,52 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Main + ( main + ) where + +import System.IO (stderr) + +import qualified Data.Text as T +import qualified Data.Text.IO as T + +import Date (getCurrentDate) +import Birthdate (readBirthdates, filterBirthday) +import Mail (mailSubject, mailBody) +import SendMail (sendMail) +import Config + +birthdatePath :: FilePath +birthdatePath = "birthdates.csv" + +configPath :: FilePath +configPath = "config.txt" + +main :: IO () +main = do + eitherBirthdates <- readBirthdates birthdatePath + eitherConfig <- getConfig configPath + case (eitherBirthdates, eitherConfig) of + (Left error, _) -> + T.hPutStr stderr $ + T.concat + [ "Error while parsing file " + , T.pack birthdatePath + , ":\n" + , error + ] + (_, Left error) -> + T.hPutStr stderr $ + T.concat + [ "Error while parsing config file " + , T.pack birthdatePath + , ":\n" + , error + ] + (Right birthdates, Right config) -> do + currentDate <- getCurrentDate + let birthdays = filterBirthday currentDate birthdates + sendMail + (mailTo config) + (mailFrom config) + (mailSubject birthdays) + (mailBody currentDate birthdays) |