return opts { opt_heartbeat = new_heartbeat }
set_help :: Options -> IO Options
-set_help opts = do
+set_help opts =
return opts { opt_help = True }
set_ignore_retweets :: Options -> IO Options
heartbeat_errors :: IO [String]
heartbeat_errors = do
hb <- parse_heartbeat
- if (isNothing hb)
- then return ["\"heartbeat\" does not appear to be an integer."]
- else return []
+ return ["\"heartbeat\" does not appear to be an integer." | isNothing hb ]
-- | Parse errors relating to the list of usernames.
username_errors :: IO [String]
username_errors = do
argv <- getArgs
let (_, usernames, _) = getOpt Permute options argv
-
- if (null usernames)
- then return ["no usernames provided."]
- else return []
+ return [ "no usernames provided." | null usernames ]
-- | Parse errors relating to the "To" address.
to_errors = do
toaddr <- parse_to_address
fromaddr <- parse_from_address
- if (isNothing toaddr) && (isJust fromaddr)
- then return ["\"from\" address specified without \"to\" address."]
- else return []
+ return ["\"from\" address specified without \"to\" address."
+ | (isNothing toaddr) && (isJust fromaddr) ]
-- | Errors for the sendmail path argument.
sendmail_path_errors = do
sendmail <- parse_sendmail_path
exists <- doesFileExist sendmail
- if (not exists)
- then return ["sendmail path does not exist"]
- else return []
+ return [ "sendmail path does not exist" | not exists ]
-- | Parse errors relating to the "From" address.
from_errors = do
toaddr <- parse_to_address
fromaddr <- parse_from_address
- if (isJust toaddr) && (isNothing fromaddr)
- then return ["\"to\" address specified without \"from\" address."]
- else return []
+ return [ "\"to\" address specified without \"from\" address."
+ | (isJust toaddr) && (isNothing fromaddr) ]
-- | Format an error message for printing.
import Control.Concurrent
import Control.Exception (evaluate)
+import Control.Monad (liftM)
import Data.List (intercalate)
import Data.Time (formatTime, getZonedTime)
import System.Exit
-- | Constructs a 'String' in RFC822 date format for the current
-- date/time.
rfc822_now :: IO String
-rfc822_now = do
- date <- getZonedTime
- return $ formatTime defaultTimeLocale rfc822DateFormat date
+rfc822_now =
+ liftM (formatTime defaultTimeLocale rfc822DateFormat) getZonedTime
+
-- errors, and exit codes. This function pretty-prints one of those
-- three-tuples.
print_sendmail_result :: (String, String, ExitCode) -> IO ()
-print_sendmail_result (outs, errs, ec) = do
+print_sendmail_result (outs, errs, ec) =
case ec of
ExitSuccess -> return ()
_ -> putStrLn $ concat ["Output: " ++ outs,
-- "since_id" parameter tacked on.
user_new_statuses_url :: String -> Integer -> String
user_new_statuses_url username last_status_id =
- concat [ user_timeline_url username,
- "&since_id=" ++ (show last_status_id) ]
-
+ url ++ "&since_id=" ++ since_id
+ where
+ url = user_timeline_url username
+ since_id = show last_status_id
get_status :: Cfg -> Integer -> IO B.ByteString
get_status cfg status_id = do
import Control.Applicative ((<$>), (<*>))
import Control.Monad (liftM)
import Data.Aeson ((.:), FromJSON(..), Value(Object))
-import Data.Maybe (fromMaybe, mapMaybe, isJust)
+import Data.Maybe (mapMaybe, isJust)
import Data.Monoid (mempty)
import Data.String.Utils (join, splitWs)
import Data.Text (pack)
show_created_at :: Maybe TimeZone -> Status -> String
show_created_at mtz =
- (fromMaybe "") . (fmap $ utc_time_to_rfc822 mtz) . created_at
+ (maybe "" (utc_time_to_rfc822 mtz)) . created_at
-- | Returns a nicely-formatted String representing the given 'Status'
-- object.