aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/twitter/twitter_lib.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-04-08 01:42:11 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2010-04-08 01:42:11 +0100
commit08579a1e871216a7bd7e50315894b6aeed6354ea (patch)
treefac993c6f54b1ccead497d1d9915ae5f5b29977d /protocols/twitter/twitter_lib.c
parent2e3a8576d6ca511df347426b4319bccde1871d06 (diff)
Parse timestamps in tweets.
Diffstat (limited to 'protocols/twitter/twitter_lib.c')
-rw-r--r--protocols/twitter/twitter_lib.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c
index 3bcb59ca..9ca4ead6 100644
--- a/protocols/twitter/twitter_lib.c
+++ b/protocols/twitter/twitter_lib.c
@@ -21,6 +21,9 @@
* *
****************************************************************************/
+/* For strptime(): */
+#define _XOPEN_SOURCE
+
#include "twitter_http.h"
#include "twitter.h"
#include "bitlbee.h"
@@ -49,7 +52,7 @@ struct twitter_xml_user {
};
struct twitter_xml_status {
- char *created_at;
+ time_t created_at;
char *text;
struct twitter_xml_user *user;
guint64 id;
@@ -71,7 +74,6 @@ static void txu_free(struct twitter_xml_user *txu)
*/
static void txs_free(struct twitter_xml_status *txs)
{
- g_free(txs->created_at);
g_free(txs->text);
txu_free(txs->user);
g_free(txs);
@@ -311,7 +313,13 @@ static xt_status twitter_xt_get_status( struct xt_node *node, struct twitter_xml
}
else if (g_strcasecmp( "created_at", child->name ) == 0)
{
- txs->created_at = g_memdup( child->text, child->text_len + 1 );
+ struct tm parsed;
+
+ /* Very sensitive to changes to the formatting of
+ this field. :-( Also assumes the timezone used
+ is UTC since C time handling functions suck. */
+ if( strptime( child->text, "%a %b %d %H:%M:%S %z %Y", &parsed ) != NULL )
+ txs->created_at = mktime_utc( &parsed );
}
else if (g_strcasecmp( "user", child->name ) == 0)
{
@@ -416,7 +424,7 @@ static void twitter_groupchat(struct im_connection *ic, GSList *list)
if (g_strcasecmp(td->user, status->user->screen_name) == 0)
imcb_chat_log (gc, "Your Tweet: %s", status->text);
else
- imcb_chat_msg (gc, status->user->screen_name, status->text, 0, 0 );
+ imcb_chat_msg (gc, status->user->screen_name, status->text, 0, status->created_at );
// Update the home_timeline_id to hold the highest id, so that by the next request
// we won't pick up the updates allready in the list.
@@ -436,7 +444,7 @@ static void twitter_private_message_chat(struct im_connection *ic, GSList *list)
for ( l = list; l ; l = g_slist_next(l) )
{
status = l->data;
- imcb_buddy_msg( ic, status->user->screen_name, status->text, 0, 0 );
+ imcb_buddy_msg( ic, status->user->screen_name, status->text, 0, status->created_at );
// Update the home_timeline_id to hold the highest id, so that by the next request
// we won't pick up the updates allready in the list.
td->home_timeline_id = td->home_timeline_id < status->id ? status->id : td->home_timeline_id;