1 -- |Functions and data for working with Twitter statuses.
11 -- |Represents one Twitter status. We don't care about any of their
13 data Status = Status { status_id :: Integer,
20 -- |Given some XML content, create a 'Status' from it.
21 status_from_content :: Content -> (Maybe Status)
22 status_from_content content =
24 if (length status_ids) == 0
25 || (length created_ats) == 0
26 || (length texts) == 0
27 || (length users) == 0
31 case first_status_id of
33 (Just status_id_data) ->
34 case first_created_at of
36 (Just created_at_data) ->
40 case (reads status_id_data :: [(Integer, String)]) of
42 parseresult:_ -> Just (Status (fst parseresult) created_at_data all_text user_object)
45 status_ids = (unique_id content)
46 first_status_id = get_char_data (status_ids !! 0)
48 created_ats = (status_created_at content)
49 first_created_at = get_char_data (created_ats !! 0)
51 texts = (status_text content)
52 all_text = concat $ catMaybes (map get_char_data texts)
54 users = (status_user content)
55 first_user = user_from_content (users !! 0)
58 -- |Takes an XML String as an argument, and returns the list of
59 -- statuses that can be parsed from it.
60 parse_statuses :: String -> [Status]
61 parse_statuses xml_data =
62 catMaybes maybe_statuses
64 (Document _ _ root _) = xmlParse xml_file_name xml_data
65 root_elem = CElem root
66 status_elements = (all_statuses root_elem)
67 maybe_statuses = map status_from_content status_elements
70 -- |This is a required parameter to the xmlParse function used in
71 -- error reporting. We're not parsing a function, though, so we leave
73 xml_file_name :: String
76 -- |Returns a nicely-formatted String representing the given 'Status'
78 pretty_print :: Status -> String
84 replicate ((length name) + 3 + (length (created_at status))) '-',
86 replace_entities (text status),
89 name = screen_name (user status)
93 -- |Given a list of statuses, returns the greatest status_id belonging
94 -- to one of the statuses in the list.
95 get_max_status_id :: [Status] -> Integer
96 get_max_status_id statuses =
99 status_ids = map status_id statuses