diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2015-03-21 18:57:23 +0900 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2015-03-21 18:57:23 +0900 |
commit | 9a1e75719481e68259e79b7bed6c6f500f0da86e (patch) | |
tree | efa18725dede445ea59a6caa8c6653eb7d085fcb /src/sariulccron.hs | |
parent | 61e7a904975518c6ab61589010dbf7b25fc21e48 (diff) | |
download | sariulclocks-9a1e75719481e68259e79b7bed6c6f500f0da86e.tar.gz |
tidy up use of IO in sariulccron main
Diffstat (limited to 'src/sariulccron.hs')
-rw-r--r-- | src/sariulccron.hs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/sariulccron.hs b/src/sariulccron.hs index d36258e..3adaf5a 100644 --- a/src/sariulccron.hs +++ b/src/sariulccron.hs @@ -17,15 +17,17 @@ weeklyCron scores = undefined main :: IO () main = runSariulClocksIO $ do scores <- readScoresFile + -- Proceed only if we actually read some scores. when (isJust scores) $ do modifyScores weeklyCron shouldModify <- liftM (((/=) scores) . Just) getScores - liftIO $ putStrLn "Scores before:\n" - liftIO $ putStrLn . ppScores $ fromJust scores - liftIO $ putStrLn "Scores after:\n" - scores' <- getScores - liftIO $ putStrLn . ppScores $ scores' - when shouldModify writeScoresFile + + when shouldModify $ do + writeScoresFile + + -- Output what we did to be e-mailed from crond. + liftM (scoresBeforeAfter (fromJust scores)) getScores + >>= printLn --- utility functions @@ -45,6 +47,9 @@ classBox (c, (Score x y)) = hsep 3 left , alignHoriz center1 7 $ (text . show) x , alignHoriz center1 12 $ (text . show) y] +scoresBeforeAfter :: ScoresList -> ScoresList -> String +scoresBeforeAfter x y = "Scores before:\n\n" ++ ppScores x ++ "\nScores after:\n\n" ++ ppScores y + isJust :: Maybe a -> Bool isJust (Just _) = True isJust _ = False |