thread_sleep heartbeat
return ()
+
+
+-- |A debugging tool that will parse, print, and email a single status
+-- (given by its id).
+twat_single_status :: Integer -> (Maybe Message) -> IO ()
+twat_single_status the_status_id maybe_message = do
+ xmldata <- get_status the_status_id
+
+ -- Parsing an empty result can blow up. Just pretend there are
+ -- no new statuses in that case.
+ let statuses = case xmldata of
+ Just xml -> parse_status xml
+ Nothing -> []
+
+ case (length statuses) of
+ 0 -> do
+ putStrLn "No statuses returned."
+ return ()
+ _ -> do
+ _ <- mapM (putStrLn . pretty_print) statuses
+
+ case maybe_message of
+ Nothing -> do
+ putStrLn "No message object given."
+ return ()
+ Just message -> do
+ date_header <- construct_date_header
+ let messages = map (message_from_status message (date_header)) statuses
+ sendmail_results <- mapM sendmail messages
+ _ <- mapM print_sendmail_result sendmail_results
+ return ()
"&include_rts=true",
"&count=10" ]
+status_url :: Integer -> String
+status_url status_id =
+ concat [ "http://api.twitter.com/1/statuses/show/",
+ (show status_id),
+ ".xml" ]
+
-- |Given username's last status id, constructs the API URL for
-- username's new statuses. Essentially, 'user_timeline_url' with a
-- "since_id" parameter tacked on.
"&since_id=" ++ (show last_status_id) ]
+get_status :: Integer -> IO (Maybe String)
+get_status status_id = do
+ let uri = (status_url status_id)
+ status <- (http_get uri)
+ return status
+
+
-- |Return's username's timeline, or 'Nothing' if there was an error.
get_user_timeline :: String -> IO (Maybe String)
get_user_timeline username = do
first_user = user_from_content (users !! 0)
+-- |Takes an XML String as an argument, and returns the
+-- status that was parsed from it. Should only be used
+-- on XML string where a <status> is a top-level element.
+parse_status :: String -> [Status]
+parse_status xml_data =
+ catMaybes maybe_status
+ where
+ (Document _ _ root _) = xmlParse xml_file_name xml_data
+ root_elem = CElem root
+ status_element = (single_status root_elem)
+ maybe_status = map status_from_content status_element
+
+
-- |Takes an XML String as an argument, and returns the list of
-- statuses that can be parsed from it.
parse_statuses :: String -> [Status]
get_char_data _ = Nothing
+-- |A 'CFilter' returning all top-level <status> elements.
+-- The name is due to the fact that if we retrieve more than
+-- one status, they will be wrapped in a <statuses> tag, and
+-- thus not be top-level.
+single_status :: CFilter
+single_status = (tag "status")
+
-- |A 'CFilter' returning all <status> tags within <statuses>.
all_statuses :: CFilter
all_statuses = (tag "statuses" /> tag "status")