mirror of
https://git.nerfingen.de/nerf/choirMail.git
synced 2025-05-15 09:50:29 +00:00
first working commit
This commit is contained in:
parent
2e2bbcd0d6
commit
0447d72e71
13 changed files with 465 additions and 0 deletions
65
app/Main.hs
Normal file
65
app/Main.hs
Normal file
|
@ -0,0 +1,65 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Main where
|
||||
|
||||
import TableParser
|
||||
import Requester
|
||||
import Config
|
||||
import Data.Time.Calendar
|
||||
import Data.Time.Clock
|
||||
import qualified Data.List as L
|
||||
import System.IO
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.IO as T
|
||||
import qualified Data.Text.Lazy as LT
|
||||
import Data.Maybe
|
||||
import System.Environment
|
||||
import System.Exit
|
||||
import Data.Time.Format.ISO8601
|
||||
import Sender
|
||||
|
||||
isChoirThisWeek :: Day -> Day -> Bool
|
||||
isChoirThisWeek today day = today <= day && diffDays day today <= 6
|
||||
|
||||
getToday :: IO Day
|
||||
getToday = utctDay <$> getCurrentTime
|
||||
|
||||
reportError :: String -> IO ()
|
||||
reportError err = hPutStr stderr err
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
args <- getArgs
|
||||
if length args /= 1
|
||||
then
|
||||
die "We need exactly one argument"
|
||||
else do
|
||||
configE <- parseFile (head args)
|
||||
case configE of
|
||||
Left text -> hPutStr stderr text
|
||||
Right config -> do
|
||||
bs <- request
|
||||
let eitherTable = parseBString bs
|
||||
case eitherTable of
|
||||
Left x -> reportError x
|
||||
Right table -> do
|
||||
today <- getToday
|
||||
maybe
|
||||
(T.putStr "Keine Probe :(")
|
||||
(\record -> send (mailDomain config) (mailUsername config) (mailPassword config) (mailTo config) (mailFrom config) (mailSubject record) (mailText record))
|
||||
(L.find ((isChoirThisWeek today) . date) table)
|
||||
|
||||
mailText :: MailRecord -> LT.Text
|
||||
mailText record = LT.fromStrict $T.concat ["Guten Morgen,\n\n"
|
||||
, announcement record
|
||||
,"\n\ndiesen Donnerstag\n\nDurchsingen: "
|
||||
,song1 record
|
||||
,", "
|
||||
,song2 record
|
||||
,"\nStimmproben: "
|
||||
,voice1 record
|
||||
,", "
|
||||
,voice2 record
|
||||
,"\n\nLG\nMalte\n" ]
|
||||
|
||||
mailSubject :: MailRecord -> T.Text
|
||||
mailSubject record = T.concat ["Donnerstag ", T.pack $ iso8601Show $ date record]
|
Loading…
Add table
Add a link
Reference in a new issue