module Web.Toboggan
( act
, program
, TwitterBot (..)
) where
import Text.Madlibs
import qualified Data.Text as T
import Web.Tweet
import Control.Monad
import System.Directory
import Options.Generic
data TwitterBot = TwitterBot { config :: FilePath <?> "Path to the .mad template"
, cred :: FilePath <?> "Path to credentials file"
, cron :: Bool <?> "Display example crontab for a twitter bot"
} deriving (Generic)
instance ParseRecord TwitterBot
act :: IO ()
act = do
twitterBot <- getRecord "Twitter bot generator"
program twitterBot
program :: TwitterBot -> IO ()
program twitterBot = do
let configR = unHelpful . config $ twitterBot
horoscope <- runFile configR
let credR = unHelpful . cred $ twitterBot
if (unHelpful . cron $ twitterBot) then do
dir <- getCurrentDirectory
putStrLn (cronStr ++ "~/.local/bin/toboggan --cred " ++ dir ++ "/" ++ credR ++ " --config " ++ dir ++ "/" ++ configR ++ "\n")
else
pure ()
void $ basicTweet (T.unpack horoscope) credR
cronStr :: String
cronStr = "\n# m h dom mon dow command\
\ 0 13 * * * "