diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2015-04-05 20:26:19 +0900 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2015-04-05 20:26:19 +0900 |
commit | 7fa6579581b6734595b0d028056998b1c96f4af4 (patch) | |
tree | cf81b3589b62c197277c431bfa5a2ce8012caf65 | |
parent | ef6658144244e5dcb319a21cfc6dbe706c7ea0be (diff) | |
download | srem-7fa6579581b6734595b0d028056998b1c96f4af4.tar.gz |
timetable reminders functionality for school
-rw-r--r-- | src/Main.hs | 2 | ||||
-rw-r--r-- | src/Utility/EventCache.hs | 19 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/Main.hs b/src/Main.hs index 21388f6..9e43724 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -37,7 +37,7 @@ import Utility.Notify doCron :: IO () doCron = do purgeOldEventCaches - rems <- (++) <$> readEmacsEventCache <*> readManualEventCache + rems <- (++) <$> readEmacsEventCache <*> ((++) <$> readManualEventCache <*> getTimetableReminders) (h, m, _) <- localHMD let nowRemsFilter r = getReminderHour r == h && getReminderMinute r == m diff --git a/src/Utility/EventCache.hs b/src/Utility/EventCache.hs index a5835db..000a3cd 100644 --- a/src/Utility/EventCache.hs +++ b/src/Utility/EventCache.hs @@ -26,19 +26,25 @@ module Utility.EventCache ( purgeOldEventCaches , refreshEmacsEventCache , readEmacsEventCache , readManualEventCache + , getTimetableReminders ) where import Control.Applicative ((<$>)) import Control.Exception (IOException, catch) import Control.Monad (filterM, forM_, when) import qualified Control.SremConfig as SremConfig -import Data.List.Split (splitOn, splitOneOf) +import Data.Char (toLower) import Data.Maybe.Read import Data.Time.Calendar +import Data.Time.Format import Data.Time.LocalTime import System.Directory (createDirectoryIfMissing, doesFileExist, getDirectoryContents, removeFile) import System.FilePath ((</>)) +import System.Locale (defaultTimeLocale) + +import Data.List.Split (splitOn, splitOneOf) + import Types.Reminder import Utility.Emacs @@ -94,6 +100,17 @@ readManualEventCache = do then readEventsCSV path else return [] +getTimetableReminders :: IO [Reminder] +getTimetableReminders = do + dayOfWeek <- map toLower . formatTime defaultTimeLocale "%A" + . localDay . zonedTimeToLocalTime <$> getZonedTime + dir <- SremConfig.getCacheDirectory + let path = dir </> dayOfWeek ++ ".csv" + exists <- doesFileExist path + if exists + then readEventsCSV path + else return [] + -- #### Internal functions readEventsCSV :: FilePath -> IO [Reminder] |