Changeset 08579a1 for protocols/twitter


Ignore:
Timestamp:
2010-04-08T00:42:11Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
37d84b3
Parents:
2e3a857
Message:

Parse timestamps in tweets.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_lib.c

    r2e3a857 r08579a1  
    2222****************************************************************************/
    2323
     24/* For strptime(): */
     25#define _XOPEN_SOURCE
     26
    2427#include "twitter_http.h"
    2528#include "twitter.h"
     
    5053
    5154struct twitter_xml_status {
    52         char *created_at;
     55        time_t created_at;
    5356        char *text;
    5457        struct twitter_xml_user *user;
     
    7275static void txs_free(struct twitter_xml_status *txs)
    7376{
    74         g_free(txs->created_at);
    7577        g_free(txs->text);
    7678        txu_free(txs->user);
     
    312314                else if (g_strcasecmp( "created_at", child->name ) == 0)
    313315                {
    314                         txs->created_at = g_memdup( child->text, child->text_len + 1 );
     316                        struct tm parsed;
     317                       
     318                        /* Very sensitive to changes to the formatting of
     319                           this field. :-( Also assumes the timezone used
     320                           is UTC since C time handling functions suck. */
     321                        if( strptime( child->text, "%a %b %d %H:%M:%S %z %Y", &parsed ) != NULL )
     322                                txs->created_at = mktime_utc( &parsed );
    315323                }
    316324                else if (g_strcasecmp( "user", child->name ) == 0)
     
    417425                        imcb_chat_log (gc, "Your Tweet: %s", status->text);
    418426                else
    419                         imcb_chat_msg (gc, status->user->screen_name, status->text, 0, 0 );
     427                        imcb_chat_msg (gc, status->user->screen_name, status->text, 0, status->created_at );
    420428               
    421429                // Update the home_timeline_id to hold the highest id, so that by the next request
     
    437445        {
    438446                status = l->data;
    439                 imcb_buddy_msg( ic, status->user->screen_name, status->text, 0, 0 );
     447                imcb_buddy_msg( ic, status->user->screen_name, status->text, 0, status->created_at );
    440448                // Update the home_timeline_id to hold the highest id, so that by the next request
    441449                // we won't pick up the updates allready in the list.
Note: See TracChangeset for help on using the changeset viewer.