Option ['t'][] (ReqArg set_to "email_address") "Send tweets TO email_address.",
Option ['f'][] (ReqArg set_from "email_address") "Send tweets FROM email_address."
]
-
+
set_help :: Options -> IO Options
set_help opts = do
set_from :: String -> Options -> IO Options
set_from arg opts = do
return opts { opt_from = Just arg }
-
+
-- The usage header.
usage :: String
parse_errors :: IO [String]
parse_errors = do
argv <- getArgs
- let (_, _, errors) = getOpt Permute options argv
+ let (_, _, errors) = getOpt Permute options argv
errs_username <- username_errors
errs_to <- to_errors
errs_from <- from_errors
opts <- parse_options
return (opt_from opts)
-
+
parse_usernames :: IO [String]
parse_usernames = do
argv <- getArgs
"\n",
(body m) ]
-
+
sendmail :: Message -> IO (String, String, ExitCode)
sendmail message = do
let sendmail_args = ["-f",
run_twat :: Maybe Message -> String -> IO ()
-run_twat message username = do
- latest_status_id <- get_latest_status_id username
+run_twat message username = do
+ latest_status_id <- get_latest_status_id username
recurse username latest_status_id message
return ()
-- Execute run_twat on each username in a new thread.
mapM (forkIO . (run_twat message)) usernames
-
+
forever $ do
-- This thread (the one executing main) doesn't do anything,
-- but when it terminates, so do all the threads we forked.
import Network.Curl
import System.IO (hPutStrLn, stderr)
---
+--
-- http://dev.twitter.com/doc/get/statuses/user_timeline
--
user_timeline_url :: String -> String
concat [ user_timeline_url username,
"&since_id=" ++ (show last_status_id) ]
-
+
get_user_timeline :: String -> IO (Maybe String)
get_user_timeline username = do
let uri = (user_timeline_url username)
new_statuses <- (http_get uri)
return new_statuses
-
+
http_get :: String -> IO (Maybe String)
http_get uri = withCurlDo $ do
resp <- curlGetString uri [CurlTimeout 45]
-
status_from_content :: Content -> (Maybe Status)
status_from_content content =
case (reads status_id_data :: [(Integer, String)]) of
[] -> Nothing
parseresult:_ -> Just (Status (fst parseresult) created_at_data all_text user_object)
-
+
where
status_ids = (unique_id content)
first_status_id = get_char_data (status_ids !! 0)
-
+
created_ats = (status_created_at content)
- first_created_at = get_char_data (created_ats !! 0)
+ first_created_at = get_char_data (created_ats !! 0)
texts = (status_text content)
all_text = concat $ catMaybes (map get_char_data texts)
-
+
users = (status_user content)
- first_user = user_from_content (users !! 0)
+ first_user = user_from_content (users !! 0)
get_max_status_id :: [Status] -> Integer
-get_max_status_id statuses =
+get_max_status_id statuses =
maximum status_ids
where
status_ids = map status_id statuses
\ No newline at end of file
data User = User { screen_name :: String }
deriving (Show, Eq)
-
+
user_from_content :: Content -> (Maybe User)
user_from_content c =
if (length names) == 0
status_user :: CFilter
status_user = keep /> (tag "user")
-
+
user_screen_name :: CFilter
user_screen_name = keep /> (tag "screen_name") /> txt