10 data Status = Status { status_id :: Integer,
19 status_from_content :: Content -> (Maybe Status)
20 status_from_content content =
22 if (length status_ids) == 0
23 || (length created_ats) == 0
24 || (length texts) == 0
25 || (length users) == 0
29 case first_status_id of
31 (Just status_id_data) ->
32 case first_created_at of
34 (Just created_at_data) ->
38 case (reads status_id_data :: [(Integer, String)]) of
40 parseresult:_ -> Just (Status (fst parseresult) created_at_data all_text user_object)
43 status_ids = (unique_id content)
44 first_status_id = get_char_data (status_ids !! 0)
46 created_ats = (status_created_at content)
47 first_created_at = get_char_data (created_ats !! 0)
49 texts = (status_text content)
50 all_text = concat $ catMaybes (map get_char_data texts)
52 users = (status_user content)
53 first_user = user_from_content (users !! 0)
57 parse_statuses :: String -> [Status]
58 parse_statuses xml_data =
59 catMaybes maybe_statuses
61 (Document _ _ root _) = xmlParse xml_file_name xml_data
62 root_elem = CElem root
63 status_elements = (all_statuses root_elem)
64 maybe_statuses = map status_from_content status_elements
67 -- This is a required parameter to the xmlParse function used in
68 -- error reporting. We're not parsing a function, though, so we
70 xml_file_name :: String
73 pretty_print :: Status -> String
79 replicate ((length name) + 3 + (length (created_at status))) '-',
81 replace_entities (text status),
84 name = screen_name (user status)
88 get_max_status_id :: [Status] -> Integer
89 get_max_status_id statuses =
92 status_ids = map status_id statuses