10 data Status = Status { status_id :: Integer,
18 status_from_content :: Content -> (Maybe Status)
19 status_from_content content =
21 if (length status_ids) == 0
22 || (length created_ats) == 0
23 || (length texts) == 0
24 || (length users) == 0
28 case first_status_id of
30 (Just status_id_data) ->
31 case first_created_at of
33 (Just created_at_data) ->
37 case (reads status_id_data :: [(Integer, String)]) of
39 parseresult:_ -> Just (Status (fst parseresult) created_at_data all_text user_object)
42 status_ids = (unique_id content)
43 first_status_id = get_char_data (status_ids !! 0)
45 created_ats = (status_created_at content)
46 first_created_at = get_char_data (created_ats !! 0)
48 texts = (status_text content)
49 all_text = concat $ catMaybes (map get_char_data texts)
51 users = (status_user content)
52 first_user = user_from_content (users !! 0)
56 parse_statuses :: String -> [Status]
57 parse_statuses xml_data =
58 catMaybes maybe_statuses
60 (Document _ _ root _) = xmlParse xml_file_name xml_data
61 root_elem = CElem root
62 status_elements = (all_statuses root_elem)
63 maybe_statuses = map status_from_content status_elements
66 -- This is a required parameter to the xmlParse function used in
67 -- error reporting. We're not parsing a function, though, so we
69 xml_file_name :: String
72 pretty_print :: Status -> String
78 replicate ((length name) + 3 + (length (created_at status))) '-',
80 replace_entities (text status),
83 name = screen_name (user status)
87 get_max_status_id :: [Status] -> Integer
88 get_max_status_id statuses =
91 status_ids = map status_id statuses