Changeset 234

Show
Ignore:
Timestamp:
03/02/06 10:56:57
Author:
miyagawa
Message:

Support persistent CookieJar? in Mixi Custom feed

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/CustomFeed/Mixi.pm

    r226 r234  
    2020    my($self, $context) = @_; 
    2121    $self->{mixi} = WWW::Mixi->new($self->conf->{email}, $self->conf->{password}); 
     22    $self->{mixi}->cookie_jar($self->cache->cookie_jar); 
    2223 
    2324    my $feed = Plagger::Feed->new; 
     
    2930    my($self, $context, $args) = @_; 
    3031 
    31     my $response = $self->{mixi}->login; 
    32     unless ($response->is_success) { 
    33         $context->log(error => "Login failed."); 
    34         return; 
     32    my $start_url = 'http://mixi.jp/new_friend_diary.pl'; 
     33    my $response  = $self->{mixi}->get($start_url); 
     34 
     35    if ($response->content =~ /action=login\.pl/) { 
     36        $context->log(debug => "Cookie not foud. Logging in"); 
     37        $response = $self->{mixi}->post("http://mixi.jp/login.pl", { 
     38            next_url => "/new_friend_diary.pl", 
     39            email    => $self->conf->{email}, 
     40            password => $self->conf->{password}, 
     41            sticky   => 'on', 
     42        }); 
     43        if (!$response->is_success || $response->content =~ /action=login\.pl/) { 
     44            $context->log(error => "Login failed."); 
     45            return; 
     46        } 
     47 
     48        # meta refresh, ugh! 
     49        if ($response->content =~ m!"0;url=(.*?)"!) { 
     50            $response = $self->{mixi}->get($1); 
     51        } 
    3552    } 
    36  
    37     $context->log(info => 'Login to mixi succeed.'); 
    3853 
    3954    my $feed = Plagger::Feed->new; 
     
    4459    my $format = DateTime::Format::Strptime->new(pattern => '%Y/%m/%d %H:%M'); 
    4560 
    46     my @msgs = $self->{mixi}->get_new_friend_diary
     61    my @msgs = $self->{mixi}->parse_new_friend_diary($response)
    4762    my $items = $self->conf->{fetch_items} || 20; 
    4863