X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTwitter%2FStatus.hs;h=01ef0ab04504596881188ebde26373281d42a1a3;hb=636deff8c41fd640cc2945eae1d7b51432527a6a;hp=6416232ebff9499bfc2d25e5bd258e8340e19ef0;hpb=e13f2a1eced5f388b37bc0ed12e9db72eba4b5d4;p=dead%2Fhalcyon.git diff --git a/src/Twitter/Status.hs b/src/Twitter/Status.hs index 6416232..01ef0ab 100644 --- a/src/Twitter/Status.hs +++ b/src/Twitter/Status.hs @@ -4,9 +4,12 @@ where import Data.Maybe import Data.String.Utils (join, splitWs) +import Data.Time (ZonedTime, formatTime, readsTime) +import System.Locale (defaultTimeLocale, rfc822DateFormat) import Test.HUnit import Text.Regex (matchRegex, mkRegex) import Text.XML.HaXml +import Text.XML.HaXml.Posn (noPos) import StringUtils (listify) import Twitter.User @@ -22,7 +25,7 @@ data Status = Status { status_id :: Integer, -- |Given some XML content, create a 'Status' from it. -status_from_content :: Content -> (Maybe Status) +status_from_content :: Content i -> (Maybe Status) status_from_content content = if (length status_ids) == 0 @@ -67,7 +70,7 @@ parse_status xml_data = catMaybes maybe_status where (Document _ _ root _) = xmlParse xml_file_name xml_data - root_elem = CElem root + root_elem = CElem root noPos status_element = (single_status root_elem) maybe_status = map status_from_content status_element @@ -79,7 +82,7 @@ parse_statuses xml_data = catMaybes maybe_statuses where (Document _ _ root _) = xmlParse xml_file_name xml_data - root_elem = CElem root + root_elem = CElem root noPos status_elements = (all_statuses root_elem) maybe_statuses = map status_from_content status_elements @@ -90,6 +93,21 @@ parse_statuses xml_data = xml_file_name :: String xml_file_name = "" + +created_at_to_rfc822 :: String -> Maybe String +created_at_to_rfc822 s = + case reads_result of + [(t,_)] -> + Just $ formatTime defaultTimeLocale rfc822DateFormat t + _ -> Nothing + where + -- Should match e.g. "Sun Oct 24 18:21:41 +0000 2010" + fmt :: String + fmt = "%a %b %d %H:%M:%S %z %Y" + + reads_result :: [(ZonedTime, String)] + reads_result = readsTime defaultTimeLocale fmt s + -- |Returns a nicely-formatted String representing the given 'Status' -- object. pretty_print :: Status -> String @@ -130,7 +148,7 @@ parse_username word = matches = matchRegex username_regex word --- |Parse all usernames of the form @username from a status. +-- |Parse all usernames of the form \@username from a status. parse_usernames_from_status :: Status -> [String] parse_usernames_from_status status = catMaybes (map parse_username status_words)