Created
February 22, 2016 01:28
-
-
Save glabra/89eb0f70b322f4780ec8 to your computer and use it in GitHub Desktop.
敗北だ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad (when, mapM_) | |
import Data.List (takeWhile, uncons) | |
import System.Environment (getArgs, getEnv) | |
import Data.Time | |
timeFormatString = "%Y%m%dT%H:%M:%S%z" | |
main :: IO () | |
main = do | |
args <- getArgs | |
now <- getCurrentTime | |
filepath <- case fst <$> uncons args of | |
Just x -> return x | |
Nothing -> (++ "/Documents/TODO") <$> getEnv "HOME" | |
l <- lines <$> readFile filepath | |
mapM_ (ikaMusume now) l | |
ikaMusume now line = | |
let dead = takeWhile (/= ',') line | |
isWarn = case dead of | |
"deadline" -> False | |
"asap" -> True | |
_ -> isExceeded now $ parse dead | |
in prettyLine isWarn line | |
isExceeded :: UTCTime -> UTCTime -> Bool | |
isExceeded now dead = (> 0) $ diffUTCTime now dead | |
parse = parseTimeOrError True defaultTimeLocale timeFormatString | |
prettyLine :: Bool -> String -> IO () | |
prettyLine warn line = do | |
when warn $ putStr "\ESC[1m" | |
putStr line | |
when warn $ putStr "\ESC[0m" | |
putStr "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment